php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81618 dns_get_record fails on FreeBSD for missing type
Submitted: 2021-11-12 19:55 UTC Modified: -
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: fsbruva at yahoo dot com Assigned:
Status: Closed Package: *Network Functions
PHP Version: Irrelevant OS: FreeBSD 12.x
Private report: No CVE-ID: None
 [2021-11-12 19:55 UTC] fsbruva at yahoo dot com
Description:
------------
On modern FreeBSD, res_nsearch() does not directly set a value for h_errno, but rather, the last h_errno value is stored as res_h_errno within the handle (statp->res_h_errno). Thus, in ext/standard/dns.c, within the definition for dns_get_record, the switch case at https://github.com/php/php-src/blob/master/ext/standard/dns.c#L981 doesn't properly categorize or catch error conditions for a particular query. Namely, instead of properly continuing to try the next record for NO_DATA or HOST_NOT_FOUND responses, the function completely fails and returns false. In my (limited) testing of this issue on Ubuntu, h_errno always equaled statp->res_h_errno, so I don't believe this fix needs to be OS dependent. 

This bug was originally reported in php 5.5.26, and is confirmed to affect 7.3.32, 7.4.25 and 8.0.12, on FreeBSD 12.2-RELEASE on amd64. See: https://bugs.php.net/bug.php?id=70027 

Test script:
---------------
php -r "var_dump(dns_get_record('www.google.com', DNS_A + DNS_CNAME));"

Expected result:
----------------
There is no CNAME record for www.google.com, so we'd only see a result for the A record.

array(1) {
  [0]=>
  array(5) {
    ["host"]=>
    string(14) "www.google.com"
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(66)
    ["type"]=>
    string(1) "A"
    ["ip"]=>
    string(12) "142.251.45.4"
  }
}


Actual result:
--------------
Warning: dns_get_record(): DNS Query failed in Command line code on line 1
bool(false)


Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-14 02:34 UTC] fsbruva at yahoo dot com
The following pull request has been associated:

Patch Name: (bugfix) dns.c: Correct dns_get_record on FreeBSD - Fix #81618
On GitHub:  https://github.com/php/php-src/pull/7653
Patch:      https://github.com/php/php-src/pull/7653.patch
 [2021-11-14 20:17 UTC] fsbruva at yahoo dot com
The following pull request has been associated:

Patch Name: (bugfix) dns.c: Correct dns_get_record on FreeBSD - Fix #81618
On GitHub:  https://github.com/php/php-src/pull/7655
Patch:      https://github.com/php/php-src/pull/7655.patch
 [2021-11-14 20:19 UTC] fsbruva at yahoo dot com
The PR php-src/7653 can be disregarded - it is closed, and is replaced by php-src/7655.
 [2021-11-15 09:05 UTC] git@php.net
Automatic comment on behalf of fsbruva (author) and nikic (committer)
Revision: https://github.com/php/php-src/commit/45f52285f6ee251dc40f31c365b0eb9e6a3e0881
Log: Fix bug #81618: Correct dns_get_record on FreeBSD
 [2021-11-15 09:05 UTC] git@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC