php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81220 gethostbyaddr returns binary garbage
Submitted: 2021-07-03 16:52 UTC Modified: 2021-07-11 04:22 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: cyr dot k at me dot com Assigned:
Status: No Feedback Package: Network related
PHP Version: 8.1Git-2021-07-03 (Git) OS: FreeBSD
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-07-03 16:52 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-03 19:26 UTC] danack@php.net
-Status: Open +Status: Feedback
 [2021-07-03 19:26 UTC] 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-11 04:22 UTC] php-bugs at lists dot php dot net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 08:01:28 2024 UTC