Skip to content

(bugfix) dns.c: Correct dns_get_record on FreeBSD - Fix #81618 #7655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ext/standard/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ PHP_FUNCTION(dns_get_record)
zend_long type_param = PHP_DNS_ANY;
zval *authns = NULL, *addtl = NULL;
int type_to_fetch;
int dns_errno;
#if defined(HAVE_DNS_SEARCH)
struct sockaddr_storage from;
uint32_t fromsize = sizeof(from);
Expand Down Expand Up @@ -940,8 +941,9 @@ PHP_FUNCTION(dns_get_record)
n = php_dns_search(handle, hostname, C_IN, type_to_fetch, answer.qb2, sizeof answer);

if (n < 0) {
dns_errno = php_dns_errno(handle);
php_dns_free_handle(handle);
switch (h_errno) {
switch (dns_errno) {
case NO_DATA:
case HOST_NOT_FOUND:
continue;
Expand Down
3 changes: 3 additions & 0 deletions ext/standard/php_dns.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
((int)dns_search(res, dname, class, type, answer, anslen, (struct sockaddr *)&from, &fromsize))
#define php_dns_free_handle(res) \
dns_free(res)
#define php_dns_errno(handle) h_errno

#elif defined(HAVE_RES_NSEARCH)
#define php_dns_search(res, dname, class, type, answer, anslen) \
Expand All @@ -39,11 +40,13 @@
res_nclose(res); \
php_dns_free_res(res)
#endif
#define php_dns_errno(handle) handle->res_h_errno

#elif defined(HAVE_RES_SEARCH)
#define php_dns_search(res, dname, class, type, answer, anslen) \
res_search(dname, class, type, answer, anslen)
#define php_dns_free_handle(res) /* noop */
#define php_dns_errno(handle) h_errno

#endif

Expand Down
12 changes: 12 additions & 0 deletions ext/standard/tests/bug81618.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Bug #81618: dns_get_record failure on FreeBSD
--FILE--
<?php
$ret = dns_get_record('www.google.com', DNS_A + DNS_CNAME);

echo ($ret !== false && count($ret) > 0);

?>

--EXPECT--
1