Skip to content

Commit 6b5e7e6

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: Fix bug #74764 and add a test case
2 parents 7585a20 + 21f8cd2 commit 6b5e7e6

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
@@ -24,6 +24,8 @@ PHP NEWS
2424
. Fixed bug #76818 (Memory corruption and segfault). (Remi)
2525
. Fixed bug #73457 (Wrong error message when fopen FTP wrapped fails to open
2626
data connection). (Ville Hukkamäki)
27+
. Fixed bug #74764 (Bindto IPv6 works with file_get_contents but fails with
28+
stream_socket_client). (Ville Hukkamäki)
2729

2830
30 Aug 2018, PHP 7.3.0beta3
2931

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
@@ -839,6 +839,9 @@ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short
839839
int local_address_len = 0;
840840

841841
if (sa->sa_family == AF_INET) {
842+
if (strchr(bindto,':')) {
843+
goto skip_bind;
844+
}
842845
struct sockaddr_in *in4 = emalloc(sizeof(struct sockaddr_in));
843846

844847
local_address = (struct sockaddr*)in4;

0 commit comments

Comments
 (0)