Skip to content

Commit d65c800

Browse files
committedSep 24, 2023
Fix GH-12190: stream_context_create with address and port at 0.
Prior to the 8.1 rewrite, inet_aton was used for ipv4 addresses therefore addresses like `0` passed. For the bindto's case where both ip and port are set as such, we discard the address binding. Close GH-12195
1 parent d93800e commit d65c800

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed
 

‎NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ PHP NEWS
3636
foreach). (nielsdos)
3737
. Fixed bug #55098 (SimpleXML iteration produces infinite loop). (nielsdos)
3838

39+
- Streams:
40+
. Fixed bug GH-12190 (binding ipv4 address with both address and port at 0).
41+
(David Carlier)
42+
3943
- XML:
4044
. Fix return type of stub of xml_parse_into_struct(). (nielsdos)
4145
. Fix memory leak when calling xml_parse_into_struct() twice. (nielsdos)
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #12190 (Setting 0 with port 0 too)
3+
--SKIPIF--
4+
<?php
5+
if (getenv("SKIP_ONLINE_TESTS")) die('skip online test');
6+
if (!in_array('https', stream_get_wrappers())) die('skip: https wrapper is required');
7+
?>
8+
--FILE--
9+
<?php
10+
$context = stream_context_create(['socket' => ['bindto' => '0:0']]);
11+
var_dump(file_get_contents('https://httpbin.org/get', false, $context) !== false);
12+
?>
13+
--EXPECT--
14+
bool(true)

‎main/network.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short
835835
case AF_INET:
836836
((struct sockaddr_in *)sa)->sin_port = htons(port);
837837
socklen = sizeof(struct sockaddr_in);
838-
if (bindto && strchr(bindto, ':')) {
838+
if (bindto && (strchr(bindto, ':') || !strcmp(bindto, "0"))) {
839839
/* IPV4 sock can not bind to IPV6 address */
840840
bindto = NULL;
841841
}

0 commit comments

Comments
 (0)