mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
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
This commit is contained in:
parent
d93800ec0f
commit
d65c80031a
3 changed files with 19 additions and 1 deletions
4
NEWS
4
NEWS
|
@ -36,6 +36,10 @@ PHP NEWS
|
||||||
foreach). (nielsdos)
|
foreach). (nielsdos)
|
||||||
. Fixed bug #55098 (SimpleXML iteration produces infinite loop). (nielsdos)
|
. Fixed bug #55098 (SimpleXML iteration produces infinite loop). (nielsdos)
|
||||||
|
|
||||||
|
- Streams:
|
||||||
|
. Fixed bug GH-12190 (binding ipv4 address with both address and port at 0).
|
||||||
|
(David Carlier)
|
||||||
|
|
||||||
- XML:
|
- XML:
|
||||||
. Fix return type of stub of xml_parse_into_struct(). (nielsdos)
|
. Fix return type of stub of xml_parse_into_struct(). (nielsdos)
|
||||||
. Fix memory leak when calling xml_parse_into_struct() twice. (nielsdos)
|
. Fix memory leak when calling xml_parse_into_struct() twice. (nielsdos)
|
||||||
|
|
14
ext/standard/tests/network/gh12190.phpt
Normal file
14
ext/standard/tests/network/gh12190.phpt
Normal file
|
@ -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)
|
|
@ -835,7 +835,7 @@ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
((struct sockaddr_in *)sa)->sin_port = htons(port);
|
((struct sockaddr_in *)sa)->sin_port = htons(port);
|
||||||
socklen = sizeof(struct sockaddr_in);
|
socklen = sizeof(struct sockaddr_in);
|
||||||
if (bindto && strchr(bindto, ':')) {
|
if (bindto && (strchr(bindto, ':') || !strcmp(bindto, "0"))) {
|
||||||
/* IPV4 sock can not bind to IPV6 address */
|
/* IPV4 sock can not bind to IPV6 address */
|
||||||
bindto = NULL;
|
bindto = NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue