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

From: Date: Sat, 03 Jul 2021 19:26:27 +0000
Subject: Bug #81220 [Opn->Fbk]: gethostbyaddr returns binary garbage
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-234789@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: danack@php.net Reported by: cyr dot k at me dot com Summary: gethostbyaddr returns binary garbage -Status: Open +Status: Feedback Type: Bug Package: Network related Operating System: FreeBSD PHP Version: 8.1Git-2021-07-03 (Git) Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#234789) next »