php / php-src

The PHP Interpreter
https://www.php.net
Other
38.23k stars 7.75k forks source link

stream_socket_get_name() can return ipv6 address even when ipv6 is not available #16117

Open nielsdos opened 1 month ago

nielsdos commented 1 month ago

Description

See https://github.com/php/php-src/pull/16115#issue-2554686741

PHP Version

PHP 8.4, perhaps lower too

Operating System

Linux

NattyNarwhal commented 1 month ago

I chased the code path since I was looking at PHP network stuff a bit ago, and it (through a ton of indirection) basically just does getsockname then calls inet_ntop on it based on the returned sockaddr's address family. There's not much additional smarts in that code path other than getting the underlying socket fd for the stream. I'm feeling this might be DNS. Probably, it resolves localhost as ::1 and tries making the socket and connecting to that, even if (for some reason) it can't.