Skip to content

Commit 21f8cd2

Browse files
committed
Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7.1: Fix bug #74764 and add a test case
2 parents 64d2978 + 0f72445 commit 21f8cd2

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.2.10
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
@@ -851,6 +851,9 @@ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short
851851
int local_address_len = 0;
852852

853853
if (sa->sa_family == AF_INET) {
854+
if (strchr(bindto,':')) {
855+
goto skip_bind;
856+
}
854857
struct sockaddr_in *in4 = emalloc(sizeof(struct sockaddr_in));
855858

856859
local_address = (struct sockaddr*)in4;

0 commit comments

Comments
 (0)