From 62c5a94c372022d4dbc483c0cb1a846c55e30dcf Mon Sep 17 00:00:00 2001 From: seliver Date: Sat, 31 Mar 2018 04:05:12 +0100 Subject: [PATCH 1/2] Fixed bug #76136 (stream_socket_get_name enclosed IPv6 in brackets) The IPv6 IP of a socket is provided by the 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. --- main/network.c | 2 +- tests/output/bug76136.phpt | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/output/bug76136.phpt diff --git a/main/network.c b/main/network.c index 8a326369a8753..23f0f140fa9c5 100644 --- a/main/network.c +++ b/main/network.c @@ -648,7 +648,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)); } diff --git a/tests/output/bug76136.phpt b/tests/output/bug76136.phpt new file mode 100644 index 0000000000000..120dd3237bbd8 --- /dev/null +++ b/tests/output/bug76136.phpt @@ -0,0 +1,11 @@ +--TEST-- +Bug #76136: stream_socket_get_name should enclose IPv6 in brackets +--FILE-- + Date: Sat, 31 Mar 2018 05:48:28 +0100 Subject: [PATCH 2/2] Bug #76136 - adjustments to test file Added PHP close tag and using expect instead of expectf --- tests/output/bug76136.phpt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/output/bug76136.phpt b/tests/output/bug76136.phpt index 120dd3237bbd8..49b6932351f63 100644 --- a/tests/output/bug76136.phpt +++ b/tests/output/bug76136.phpt @@ -6,6 +6,7 @@ $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); ---EXPECTF-- +?> +--EXPECT-- [::1]:1337 -127.0.0.1:1337 \ No newline at end of file +127.0.0.1:1337