Skip to content

Fix GH-12190: stream_context_create with address and port at 0. #12195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ext/standard/tests/network/gh12190.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Bug #12190 (Setting 0 with port 0 too)
--SKIPIF--
<?php
if (getenv("SKIP_ONLINE_TESTS")) die('skip online test');
if (!in_array('https', stream_get_wrappers())) die('skip: https wrapper is required');
?>
--FILE--
<?php
$context = stream_context_create(['socket' => ['bindto' => '0:0']]);
var_dump(file_get_contents('https://httpbin.org/get', false, $context) !== false);
?>
--EXPECT--
bool(true)
2 changes: 1 addition & 1 deletion main/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short
case AF_INET:
((struct sockaddr_in *)sa)->sin_port = htons(port);
socklen = sizeof(struct sockaddr_in);
if (bindto && strchr(bindto, ':')) {
if (bindto && (strchr(bindto, ':') || !strcmp(bindto, "0"))) {
/* IPV4 sock can not bind to IPV6 address */
bindto = NULL;
}
Expand Down