Skip to content

Commit 7daf012

Browse files
committed
Fix GH-7748: gethostbyaddr outputs binary string
`getnameinfo(3)` returns zero on success; all other values need to be regarded as failure.
1 parent cfcee97 commit 7daf012

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ PHP NEWS
3131
. Fixed bug #75917 (SplFileObject::seek broken with CSV flags). (Aliaksandr
3232
Bystry)
3333

34+
- Standard:
35+
. Fixed bug GH-7748 (gethostbyaddr outputs binary string). (cmb)
36+
3437
02 Dec 2021, PHP 8.1.1
3538

3639
- IMAP:

ext/standard/dns.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,14 @@ static zend_string *php_gethostbyaddr(char *ip)
182182
if (inet_pton(AF_INET6, ip, &sa6.sin6_addr)) {
183183
sa6.sin6_family = AF_INET6;
184184

185-
if (getnameinfo((struct sockaddr *)&sa6, sizeof(sa6), out, sizeof(out), NULL, 0, NI_NAMEREQD) < 0) {
185+
if (getnameinfo((struct sockaddr *)&sa6, sizeof(sa6), out, sizeof(out), NULL, 0, NI_NAMEREQD) != 0) {
186186
return zend_string_init(ip, strlen(ip), 0);
187187
}
188188
return zend_string_init(out, strlen(out), 0);
189189
} else if (inet_pton(AF_INET, ip, &sa4.sin_addr)) {
190190
sa4.sin_family = AF_INET;
191191

192-
if (getnameinfo((struct sockaddr *)&sa4, sizeof(sa4), out, sizeof(out), NULL, 0, NI_NAMEREQD) < 0) {
192+
if (getnameinfo((struct sockaddr *)&sa4, sizeof(sa4), out, sizeof(out), NULL, 0, NI_NAMEREQD) != 0) {
193193
return zend_string_init(ip, strlen(ip), 0);
194194
}
195195
return zend_string_init(out, strlen(out), 0);

0 commit comments

Comments
 (0)