Skip to content

Commit 0f72445

Browse files
Ville Hukkamakikrakjoe
Ville Hukkamaki
authored andcommitted
Fix bug #74764 and add a test case
1 parent e58690a commit 0f72445

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ PHP NEWS
1212
- Standard:
1313
. Fixed bug #73457 (Wrong error message when fopen FTP wrapped fails to open
1414
data connection). (Ville Hukkamäki)
15+
. Fixed bug #74764 (Bindto IPv6 works with file_get_contents but fails with
16+
stream_socket_client). (Ville Hukkamäki)
1517

1618
13 Sep 2018, PHP 7.1.22
1719

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #74764 IPv6 bindto fails with stream_socket_client()
3+
--SKIPIF--
4+
<?php
5+
/* following copied straight from the tcp6loop.phpt */
6+
@stream_socket_client('tcp://[::1]:0', $errno);
7+
if ($errno != 111) die('skip IPv6 not supported.');
8+
?>
9+
--FILE--
10+
<?php
11+
$context = stream_context_create(
12+
['socket' => array('bindto' => "[::]:0")]
13+
);
14+
$socket = stream_socket_client('tcp://localhost:1443', $errno, $errstr, 5, STREAM_CLIENT_CONNECT, $context);
15+
16+
$context = stream_context_create(
17+
array('socket' => array('bindto' => "0.0.0.0:0"))
18+
);
19+
$socket = stream_socket_client('tcp://localhost:1443', $errno, $errstr, 5, STREAM_CLIENT_CONNECT, $context);
20+
?>
21+
--EXPECTF--
22+
Warning: stream_socket_client(): unable to connect to tcp://localhost:1443 (%s) in %s on line %d
23+
24+
Warning: stream_socket_client(): unable to connect to tcp://localhost:1443 (%s) in %s on line %d

main/network.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,9 @@ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short
863863
int local_address_len = 0;
864864

865865
if (sa->sa_family == AF_INET) {
866+
if (strchr(bindto,':')) {
867+
goto skip_bind;
868+
}
866869
struct sockaddr_in *in4 = emalloc(sizeof(struct sockaddr_in));
867870

868871
local_address = (struct sockaddr*)in4;

0 commit comments

Comments
 (0)