Edit report at https://bugs.php.net/bug.php?id=80067&edit=1
ID: 80067
Updated by: requinix@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
+Status: Open
Type: Bug
Package: Sockets related
Operating System: macOS 10.15
PHP Version: 7.4.10
Block user comment: N
Private report: N
New Comment:
> So my understanding is, I can provide either just the IP address or just the
> port or both.
We could blame poor phrasing on the docs' part, but the very next sentence says:
> The syntax is ip:port for IPv4 addresses, and [ip]:port for IPv6 addresses.
To me, that indicates a specification which will supersede just about anything else that might be
stated.
This is also when I notice that I totally misunderstood that second syntax. The [] brackets are
required because it's for IPv6 - they don't mean the address half is optional.
So actually, according to the docs, the two syntaxes would be "0:0" for IPv4 and
"[0]:0" for IPv6.
Not saying that "0" / "[0]" and ":0" / "[]:0" should not be
allowed; I don't care either way, though I don't see why they shouldn't be. I'm
just questioning why Symfony was relying on undocumented behavior.
Naturally, assuming this break does get fixed, the docs need to be updated.
Previous Comments:
------------------------------------------------------------------------
[2020-09-06 21:57:36] nikic@php.net
Possibly caused by https://github.com/php/php-src/pull/5903.
------------------------------------------------------------------------
[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