Skip to content

Commit

Permalink
Fix GH-7748: gethostbyaddr outputs binary string
Browse files Browse the repository at this point in the history
`getnameinfo(3)` returns zero on success; all other values need to be
regarded as failure.
  • Loading branch information
cmb69 committed Dec 10, 2021
1 parent cfcee97 commit 7daf012
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ PHP NEWS
. Fixed bug #75917 (SplFileObject::seek broken with CSV flags). (Aliaksandr
Bystry)

- Standard:
. Fixed bug GH-7748 (gethostbyaddr outputs binary string). (cmb)

02 Dec 2021, PHP 8.1.1

- IMAP:
Expand Down
4 changes: 2 additions & 2 deletions ext/standard/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,14 @@ static zend_string *php_gethostbyaddr(char *ip)
if (inet_pton(AF_INET6, ip, &sa6.sin6_addr)) {
sa6.sin6_family = AF_INET6;

if (getnameinfo((struct sockaddr *)&sa6, sizeof(sa6), out, sizeof(out), NULL, 0, NI_NAMEREQD) < 0) {
if (getnameinfo((struct sockaddr *)&sa6, sizeof(sa6), out, sizeof(out), NULL, 0, NI_NAMEREQD) != 0) {
return zend_string_init(ip, strlen(ip), 0);
}
return zend_string_init(out, strlen(out), 0);
} else if (inet_pton(AF_INET, ip, &sa4.sin_addr)) {
sa4.sin_family = AF_INET;

if (getnameinfo((struct sockaddr *)&sa4, sizeof(sa4), out, sizeof(out), NULL, 0, NI_NAMEREQD) < 0) {
if (getnameinfo((struct sockaddr *)&sa4, sizeof(sa4), out, sizeof(out), NULL, 0, NI_NAMEREQD) != 0) {
return zend_string_init(ip, strlen(ip), 0);
}
return zend_string_init(out, strlen(out), 0);
Expand Down

0 comments on commit 7daf012

Please sign in to comment.