Skip to content

Commit ce5bdfc

Browse files
committed
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.
1 parent 5286bab commit ce5bdfc

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
Lines changed: 14 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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)