Skip to content

Commit 32ecdb5

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix bug #81618: Correct dns_get_record on FreeBSD
2 parents 0993821 + 822047f commit 32ecdb5

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

ext/standard/dns.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,7 @@ PHP_FUNCTION(dns_get_record)
829829
zend_long type_param = PHP_DNS_ANY;
830830
zval *authns = NULL, *addtl = NULL;
831831
int type_to_fetch;
832+
int dns_errno;
832833
#if defined(HAVE_DNS_SEARCH)
833834
struct sockaddr_storage from;
834835
uint32_t fromsize = sizeof(from);
@@ -977,8 +978,9 @@ PHP_FUNCTION(dns_get_record)
977978
n = php_dns_search(handle, hostname, C_IN, type_to_fetch, answer.qb2, sizeof answer);
978979

979980
if (n < 0) {
981+
dns_errno = php_dns_errno(handle);
980982
php_dns_free_handle(handle);
981-
switch (h_errno) {
983+
switch (dns_errno) {
982984
case NO_DATA:
983985
case HOST_NOT_FOUND:
984986
continue;

ext/standard/php_dns.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
((int)dns_search(res, dname, class, type, (char *) answer, anslen, (struct sockaddr *)&from, &fromsize))
2525
#define php_dns_free_handle(res) \
2626
dns_free(res)
27+
#define php_dns_errno(handle) h_errno
2728

2829
#elif defined(HAVE_RES_NSEARCH)
2930
#define php_dns_search(res, dname, class, type, answer, anslen) \
@@ -37,11 +38,13 @@
3738
res_nclose(res); \
3839
php_dns_free_res(res)
3940
#endif
41+
#define php_dns_errno(handle) handle->res_h_errno
4042

4143
#elif defined(HAVE_RES_SEARCH)
4244
#define php_dns_search(res, dname, class, type, answer, anslen) \
4345
res_search(dname, class, type, answer, anslen)
4446
#define php_dns_free_handle(res) /* noop */
47+
#define php_dns_errno(handle) h_errno
4548

4649
#endif
4750

Lines changed: 15 additions & 0 deletions
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)