]> granicus.if.org Git - php/commitdiff
Handle bindto error
authortwosee <twose@qq.com>
Wed, 29 Jul 2020 04:59:44 +0000 (12:59 +0800)
committertwosee <twose@qq.com>
Wed, 29 Jul 2020 09:46:27 +0000 (17:46 +0800)
Closes GH-5903.

ext/standard/tests/network/bindto.phpt [new file with mode: 0644]
main/streams/xp_socket.c

diff --git a/ext/standard/tests/network/bindto.phpt b/ext/standard/tests/network/bindto.phpt
new file mode 100644 (file)
index 0000000..bfff64a
--- /dev/null
@@ -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
index 0ae0c0f77bfe68bc938dba69be870caab8c6d098..4bca670b84956100a93c4758b6d72ca80b072f66 100644 (file)
@@ -744,6 +744,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