Skip to content

Commit 45f5228

Browse files
fsbruvanikic
authored andcommitted
Fix bug #81618: Correct dns_get_record on FreeBSD
Modify dns_get_record to test for records result based on dns_errno to accommodate modern FreeBSD, for which res_nsearch() does not update h_errno directly. Add new php_dns_errno macro, and have it consult statp->res_h_errno when OS has res_nsearch(). Closes GH-7655.
1 parent ca87d46 commit 45f5228

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ PHP NEWS
99
- GD:
1010
. Fixed bug #71316 (libpng warning from imagecreatefromstring). (cmb)
1111

12+
- Standard:
13+
. Fixed bug #81618 (dns_get_record fails on FreeBSD for missing type).
14+
(fsbruva)
15+
1216
18 Nov 2021, PHP 7.4.26
1317

1418
- Core:

ext/standard/dns.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ PHP_FUNCTION(dns_get_record)
808808
zend_long type_param = PHP_DNS_ANY;
809809
zval *authns = NULL, *addtl = NULL;
810810
int type_to_fetch;
811+
int dns_errno;
811812
#if defined(HAVE_DNS_SEARCH)
812813
struct sockaddr_storage from;
813814
uint32_t fromsize = sizeof(from);
@@ -957,8 +958,9 @@ PHP_FUNCTION(dns_get_record)
957958
n = php_dns_search(handle, hostname, C_IN, type_to_fetch, answer.qb2, sizeof answer);
958959

959960
if (n < 0) {
961+
dns_errno = php_dns_errno(handle);
960962
php_dns_free_handle(handle);
961-
switch (h_errno) {
963+
switch (dns_errno) {
962964
case NO_DATA:
963965
case HOST_NOT_FOUND:
964966
continue;

ext/standard/php_dns.h

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
((int)dns_search(res, dname, class, type, (char *) answer, anslen, (struct sockaddr *)&from, &fromsize))
2727
#define php_dns_free_handle(res) \
2828
dns_free(res)
29+
#define php_dns_errno(handle) h_errno
2930

3031
#elif defined(HAVE_RES_NSEARCH)
3132
#define php_dns_search(res, dname, class, type, answer, anslen) \
@@ -39,11 +40,13 @@
3940
res_nclose(res); \
4041
php_dns_free_res(res)
4142
#endif
43+
#define php_dns_errno(handle) handle->res_h_errno
4244

4345
#elif defined(HAVE_RES_SEARCH)
4446
#define php_dns_search(res, dname, class, type, answer, anslen) \
4547
res_search(dname, class, type, answer, anslen)
4648
#define php_dns_free_handle(res) /* noop */
49+
#define php_dns_errno(handle) h_errno
4750

4851
#endif
4952

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #81618: dns_get_record failure on FreeBSD
3+
--SKIPIF--
4+
<?php
5+
if (getenv('SKIP_ONLINE_TESTS')) die('skip online test');
6+
?>
7+
--FILE--
8+
<?php
9+
$ret = dns_get_record('www.google.com', DNS_A + DNS_CNAME);
10+
11+
echo ($ret !== false && count($ret) > 0);
12+
13+
?>
14+
--EXPECT--
15+
1

0 commit comments

Comments
 (0)