php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81441 gethostbyaddr('::1') returns ip instead of name after calling some other method
Submitted: 2021-09-15 18:16 UTC Modified: 2021-11-09 15:25 UTC
From: stefan at buerk dot tech Assigned: nikic (profile)
Status: Closed Package: *Network Functions
PHP Version: 8.1.0RC1 OS: alpine-3.13/alpine-3.14 docker
Private report: No CVE-ID: None
 [2021-09-15 18:16 UTC] stefan at buerk dot tech
Description:
------------
We have tried to use the alpine docker images for our ci builds to start getting 8.1 compatibility. We had a weired behaviour with using gethostbyaddr('::1') in unit tests.

The first call is resolved to 'localhost', or better to say all calls until one other function where called. (Do not know if all, but we had different in between). For  example the version_compare(), as this was the first function in phpunit .. which changed the behavior.

Maybe it is not php, but we used the same dockerfile as verification, kust switchen php 8 with 8.1 RC1 and getting this weired behaviour. We opend an issue on github for the php docker containers holding a lot of test runs.

https://github.com/docker-library/php/issues/1201



Test script:
---------------
<?php
echo "CHECK ::1 hostname before/after version compare" . PHP_EOL;

// duplicationg this line bevore other code lines, would work until something
// like version_compare is used.
// EXPECTED: localhost
echo "#1 IPv6(::1): " . (string)gethostbyaddr('::1') . PHP_EOL;

// this line chanes the return in 8.1.0RC1-alpine - but why ?
// but even other codelines changed it
if (!version_compare(PHP_VERSION, PHP_VERSION, '=')) {}

// EXPECTED: localhost => alpine ::1, others localhost as expected
echo "#2 IPv6(::1): " . (string)gethostbyaddr('::1') . PHP_EOL;

Expected result:
----------------
Getting always the resolved name from /etc/hosts on subsequent calls, even if other scripts are called:

CHECK ::1 hostname before/after version compare
#1 IPv6(::1): localhost
#2 IPv6(::1): localhost

Actual result:
--------------
CHECK ::1 hostname before/after version compare
#1 IPv6(::1): localhost
#2 IPv6(::1): ::1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-26 13:44 UTC] cmb@php.net
Relevant info from the (now closed) downstream issue:
<https://github.com/docker-library/php/issues/1201#issuecomment-922939722>f.
 [2021-11-03 22:17 UTC] stefan at buerk dot tech
This issue still exists in official php alpine xxx 8.1 RC5 containers.
 [2021-11-09 15:23 UTC] git@php.net
Automatic comment on behalf of nikic
Revision: https://github.com/php/php-src/commit/425e70c11c29b313ab69e252329ef75f4f2c1a49
Log: Fix bug #81441
 [2021-11-09 15:23 UTC] git@php.net
-Status: Open +Status: Closed
 [2021-11-09 15:25 UTC] nikic@php.net
-Assigned To: +Assigned To: nikic
 [2021-11-09 15:25 UTC] nikic@php.net
I wasn't able to reproduce the specific behavior, but did see an uninitialized memory warning under valgrind. Specifically https://github.com/ifduyue/musl/blob/cfdfd5ea3ce14c6abf7fb22a531f3d99518b5a1b/src/network/getnameinfo.c#L71 compares sin6_scope_id loaded in https://github.com/ifduyue/musl/blob/cfdfd5ea3ce14c6abf7fb22a531f3d99518b5a1b/src/network/getnameinfo.c#L146. To be conservative, I'm now zeroing the structure.

I assume this will fix the issue on your side as well, please tell me if that's not the case.
 [2021-11-11 22:55 UTC] stefan at buerk dot tech
Just to report back. Retested today, it seems that the issue is fixed now. Manual testcase with alpine docker images working and we can reactivate the test in the Typo3 testings then.

Thanks for fixing this issue.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Aug 14 04:05:44 2022 UTC