summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/standard/tests/network/bindto.phpt16
-rw-r--r--main/streams/xp_socket.c4
2 files changed, 20 insertions, 0 deletions
diff --git a/ext/standard/tests/network/bindto.phpt b/ext/standard/tests/network/bindto.phpt
new file mode 100644
index 0000000000..bfff64a5e0
--- /dev/null
+++ b/ext/standard/tests/network/bindto.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Test invalid bindto
+--FILE--
+<?php
+$ctx = stream_context_create([
+ 'socket' => [
+ 'bindto' => 'invalid',
+ ],
+]);
+$fp = stream_socket_client(
+ 'tcp://www.' . str_repeat('x', 100) . '.com:80',
+ $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $ctx
+);
+?>
+--EXPECTF--
+Warning: stream_socket_client(): Unable to connect to tcp://%s:80 (Failed to parse address "invalid") in %s on line %d
diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c
index 46b23b63ad..5313a84b72 100644
--- a/main/streams/xp_socket.c
+++ b/main/streams/xp_socket.c
@@ -750,6 +750,10 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_
return -1;
}
bindto = parse_ip_address_ex(Z_STRVAL_P(tmpzval), Z_STRLEN_P(tmpzval), &bindport, xparam->want_errortext, &xparam->outputs.error_text);
+ if (bindto == NULL) {
+ efree(host);
+ return -1;
+ }
}
#ifdef SO_BROADCAST