Bug #81220 [Fbk->NoF]: gethostbyaddr returns binary garbage

From: Date: Sun, 11 Jul 2021 04:22:13 +0000
Subject: Bug #81220 [Fbk->NoF]: gethostbyaddr returns binary garbage
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-234948@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81220&edit=1

 ID:               81220
 Updated by:       php-bugs@lists.php.net
 Reported by:      cyr dot k at me dot com
 Summary:          gethostbyaddr returns binary garbage
-Status:           Feedback
+Status:           No Feedback
 Type:             Bug
 Package:          Network related
 Operating System: FreeBSD
 PHP Version:      8.1Git-2021-07-03 (Git)
 Private report:   N

 New Comment:

No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.


Previous Comments:
------------------------------------------------------------------------
[2021-07-03 19:26:27] danack@php.net

I couldn't replicate that behaviour. This is likely to be something peculiar to your own
system. 

The code is just returning the name returned by the system call: https://github.com/php/php-src/blob/aff365871aec54c9a556d7667f131b8638d20194/ext/standard/dns.c#L204-L206

Can you use the code below, or something similar to dump the actual characters as they might shed
some insight:

function showRawCharacters($result) {
    $resultInHex = unpack('H*', $result);
    $resultInHex = $resultInHex[1];
    $resultSeparated = implode(', ', str_split($resultInHex, 2)); //byte safe
    echo $resultSeparated;
}


You could also confirm that the 'garbage' is coming from a system call by running the test
script through strace e.g. strace php debug.php, to double-check that there isn't
something super weird going on.

------------------------------------------------------------------------
[2021-07-03 16:52:46] cyr dot k at me dot com

Description:
------------
gethostbyaddr("109.197.205.75"), for example, returns four seemingly random bytes string
(no, it's not a binary presentation of IPv4 address).
Addresses with proper reverse DNS records still return them as expected, this one IP doesn't
have it.

Test script:
---------------
<?php
file_put_contents("/tmp/wtf.bin", gethostbyaddr("109.197.205.75"));
?>


Expected result:
----------------
Should just return the IP if it cannot find a name for it.

Actual result:
--------------
garbage


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=81220&edit=1


Thread (3 messages)

« previous php.bugs (#234948) next »