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: -
From: stefan at buerk dot tech Assigned:
Status: Open Package: *Network Functions
PHP Version: 8.1.0RC1 OS: alpine-3.13/alpine-3.14 docker
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: stefan at buerk dot tech
New email:
PHP Version: OS:

 

 [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

 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Oct 25 18:03:49 2021 UTC