Bug #80067 [Fbk]: Omitting the port in bindto setting results in "Failed to parse address" error
| From: | nikic@php.net | Date: | Sun, 06 Sep 2020 21:57:36 +0000 |
| Subject: | Bug #80067 [Fbk]: Omitting the port in bindto setting results in "Failed to parse address" error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-228905@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80067&edit=1
ID: 80067
Updated by: nikic@php.net
Reported by: me at derrabus dot de
Summary: Omitting the port in bindto setting results in
"Failed to parse address" error
Status: Feedback
Type: Bug
Package: Sockets related
Operating System: macOS 10.15
PHP Version: 7.4.10
Block user comment: N
Private report: N
New Comment:
Possibly caused by https://github.com/php/php-src/pull/5903.
Previous Comments:
------------------------------------------------------------------------
[2020-09-06 21:49:18] me at derrabus dot de
> The documentation doesn't actually say that "0" is allowed.
Your quote says:
> the IP address (either IPv4 or IPv6) and/or the port number
So my understanding is, I can provide either just the IP address or just the port or both. Omitting
the port seems valid to me. Your suggestion ":0" also triggers a warning by the way,
although the actual operation succeeds.
But this discussion is a bit beside the point: if providing the port had always been mandatory, I
would not file a bug ticket here. But it wasn't until recently. My point is that this change is
quite heavy for a bugfix release and it breaks a widely used library.
------------------------------------------------------------------------
[2020-09-06 21:20:01] requinix@php.net
The documentation doesn't actually say that "0" is allowed.
https://www.php.net/manual/en/context.socket.php
> Used to specify the IP address (either IPv4 or IPv6) and/or the port number that
> PHP will use to access the network. The syntax is ip:port for IPv4 addresses,
> and [ip]:port for IPv6 addresses. Setting the IP or the port to 0 will let the
> system choose the IP and/or port.
Thus the allowed values are "0:0" and ":0".
------------------------------------------------------------------------
[2020-09-06 21:17:00] me at derrabus dot de
Description:
------------
Before php 7.4.10, it was possible to provide a "bindto" setting without a port via the
socket stream context. With 7.4.10, a warning is raised and the stream is not opened.
This breaks Symfony's HttpClient component, see https://github.com/symfony/symfony/issues/38081
for details.
The attached test script reproduces the regression. Executing it on php 7.4.9 produces the expected
result. On php 7.4.10, the script fails. If you change the "bindto" setting to
"0:0", the script passes on both versions, 7.4.9 and 7.4.10.
Test script:
---------------
<?php
$context = stream_context_create(['socket' => ['bindto' =>
'0']]);
var_dump(file_get_contents('https://httpbin.org/get', false, $context));
Expected result:
----------------
string(200) "{
"args": {},
"headers": {
"Host": "httpbin.org"
},
"origin": "1.2.3.4",
"url": "https://httpbin.org/get"
}
Actual result:
--------------
Warning: file_get_contents(https://httpbin.org/get): failed to open stream: Failed to parse address
"0" in /app/test.php on line 4
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80067&edit=1