]> granicus.if.org Git - php/commitdiff
Fixed bug #76136 (stream_socket_get_name enclosed IPv6 in brackets)
authorseliver <alexeyseliverstov.dev@gmail.com>
Sat, 31 Mar 2018 03:05:12 +0000 (04:05 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Sat, 7 Jul 2018 09:47:50 +0000 (11:47 +0200)
The IPv6 IP of a socket is provided by inet_ntop() as a string, but
this function doesn't enclose the IP in brackets. This patch adds
them in the php_network_populate_name_from_sockaddr() function.

NEWS
UPGRADING
ext/standard/tests/streams/bug76136.phpt [new file with mode: 0644]
main/network.c

diff --git a/NEWS b/NEWS
index 7184825e4f5eeb583e52cca27c4ffd0991af7646..ceb47808733560925100b104e3541ebbe0e70f40 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,10 @@ PHP                                                                        NEWS
     for FIREBIRD >= 3.0). (Dorin Marcoci)
   . Fixed bug #76488 (Memory leak when fetching a BLOB field). (Simonov Denis)
 
+- Standard:
+  . Fixed bug #76136 (stream_socket_get_name should enclose IPv6 in brackets).
+    (seliver)
+
 05 Jul 2018, PHP 7.3.0alpha3
 
 - Core:
index 98daa08670bd7d41b1aacd2f2a295ae1b0a9f94e..54bb277e66ed09627264f6056fd2e7bd237acb05 100644 (file)
--- a/UPGRADING
+++ b/UPGRADING
@@ -152,8 +152,10 @@ SimpleXML:
 Standard:
   . Undefined variables passed to compact() will now be reported as a notice.
   . getimagesize() and related functions now report the mime type of BMP images
-         as image/bmp instead of image/x-ms-bmp, since the former has been registered
-               with the IANA (see RFC 7903).
+    as image/bmp instead of image/x-ms-bmp, since the former has been registered
+    with the IANA (see RFC 7903).
+  . stream_socket_get_name() will now return IPv6 addresses wrapped in brackets.
+    For example "[::1]:1337" will be returned instead of "::1:1337".
 
 ========================================
 2. New Features
diff --git a/ext/standard/tests/streams/bug76136.phpt b/ext/standard/tests/streams/bug76136.phpt
new file mode 100644 (file)
index 0000000..687d4ae
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+Bug #76136: stream_socket_get_name should enclose IPv6 in brackets
+--SKIPIF--
+<?php
+@stream_socket_client('tcp://[::1]:0', $errno);
+if ($errno != 111) {
+    die('skip IPv6 is not supported.');
+}
+?>
+--FILE--
+<?php
+$server = stream_socket_server("tcp://[::1]:1337/");
+echo stream_socket_get_name($server, false).PHP_EOL;
+$server = stream_socket_server("tcp://127.0.0.1:1337/");
+echo stream_socket_get_name($server, false);
+?>
+--EXPECT--
+[::1]:1337
+127.0.0.1:1337
index 03ceb2ad083537de77a098045cca0696fe81d0a6..b31e9d659bb138ad73a6f5975f4fdf2d0b7a5f7c 100644 (file)
@@ -626,7 +626,7 @@ PHPAPI void php_network_populate_name_from_sockaddr(
                        case AF_INET6:
                                buf = (char*)inet_ntop(sa->sa_family, &((struct sockaddr_in6*)sa)->sin6_addr, (char *)&abuf, sizeof(abuf));
                                if (buf) {
-                                       *textaddr = strpprintf(0, "%s:%d",
+                                       *textaddr = strpprintf(0, "[%s]:%d",
                                                buf, ntohs(((struct sockaddr_in6*)sa)->sin6_port));
                                }