Skip to content

Commit 71f50f1

Browse files
committed
Fix bug #81618: dns_get_record failure on FreeBSD
when query for a record type fails. from fsbruva's insights.
1 parent 64fde17 commit 71f50f1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

ext/standard/dns.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -946,8 +946,11 @@ PHP_FUNCTION(dns_get_record)
946946
n = php_dns_search(handle, hostname, C_IN, type_to_fetch, answer.qb2, sizeof answer);
947947

948948
if (n < 0) {
949-
php_dns_free_handle(handle);
949+
#if defined(HAVE_RES_NSEARCH)
950+
switch (handle->res_h_errno) {
951+
#else
950952
switch (h_errno) {
953+
#endif
951954
case NO_DATA:
952955
case HOST_NOT_FOUND:
953956
continue;
@@ -963,6 +966,7 @@ PHP_FUNCTION(dns_get_record)
963966
default:
964967
php_error_docref(NULL, E_WARNING, "DNS Query failed");
965968
}
969+
php_dns_free_handle(handle);
966970
zend_array_destroy(Z_ARR_P(return_value));
967971
RETURN_FALSE;
968972
}

ext/standard/tests/bug81618.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug #81618: dns_get_record failure on FreeBSD
3+
--FILE--
4+
<?php
5+
$ret = dns_get_record('www.google.com', DNS_A + DNS_CNAME);
6+
7+
echo ($ret !== false && count($ret) > 0);
8+
9+
?>
10+
11+
--EXPECT--
12+
1

0 commit comments

Comments
 (0)