Bug #81618 [Com]: dns_get_record fails on FreeBSD for missing type

From: Date: Sun, 14 Nov 2021 20:19:04 +0000
Subject: Bug #81618 [Com]: dns_get_record fails on FreeBSD for missing type
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237756@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81618&edit=1

 ID:                 81618
 Comment by:         fsbruva at yahoo dot com
 Reported by:        fsbruva at yahoo dot com
 Summary:            dns_get_record fails on FreeBSD for missing type
 Status:             Open
 Type:               Bug
 Package:            *Network Functions
 Operating System:   FreeBSD 12.x
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

The PR php-src/7653 can be disregarded - it is closed, and is replaced by php-src/7655.


Previous Comments:
------------------------------------------------------------------------
[2021-11-14 20:17:22] 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 02:34:22] 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-12 19:55:59] 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)



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=81618&edit=1


Thread (5 messages)

« previous php.bugs (#237756) next »