Home » Networking » Net_DNS » Bug #3927
Net_DNS ignoring authority section
Details
| Submitted | 2005-03-23 12:17 UTC |
|---|---|
| From | jcardona at allglobalnames dot com |
| Assigned | ekilfoil |
| Status | Bogus |
| Package | Net_DNS |
| PHP Version | 4.3.10 |
| OS | Linux |
| Roadmaps | (Not assigned) |
Comments
[2005-03-23 12:17 UTC] jcardona at allglobalnames dot com
Description:
------------
I've noticed that Resolver.php is failing (return false) when querying nameservers that only return authority section (but no answer). It should recurse (if $recurse is set) or return such authority section.
i.e.: co.uk servers do this.
when querying for nameservers for coca-cola.co.uk (and other) it fails instead of returning the authority section which contain the correct nameservers.
In fact I've noticed that 'host' works similarly but 'dig' does return the correct answers.
I've patched this behaviour by changing line 607 (+ or -) in Resolver.php
Original:
if (is_object($ans) && $ans->header->ancount > 0) {
Patched:
if (is_object($ans) && ($ans->header->ancount > 0 || $ans->header->nscount > 0 )) {
Sorry, dont know how to use diff and too lazy/busy/whatever to learn ;-)
Reproduce code:
---------------
<?php
require_once ( "Net/DNS.php" );
$resolver = new Net_DNS_Resolver();
// We set the co.uk nameservers as resolvers (dig -t ns co.uk.)
$resolver->nameservers = array ( "ns1.nic.uk", "ns2.nic.uk", "ns3.nic.uk", "ns4.nic.uk", "ns5.nic.uk", "ns6.nic.uk", "ns7.nic.uk", "nsa.nic.uk", "nsb.nic.uk" );
if ( $resolver->query ( "coca-cola.co.uk", "NS" ) )
echo "Worked\n";
else
echo "Failed\n";
?>
Expected result:
----------------
Worked
Actual result:
--------------
Failed
[2005-04-01 16:34 UTC] cox at idecnet dot com
Maybe this one is related to http://pear.php.net/bugs/bug.php?id=4025 too. Could you try with the suggested patch?
Tomas V.V.Cox
[2005-04-04 10:32 UTC] jcardona at allglobalnames dot com
Suggested patch in http://pear.php.net/bugs/bug.php?id=4025 does not solve the problem.
Problem is in Resolver.php query() function that does not check answer in nscount (only checks ancount).
So where it says (line 607):
if (is_object($ans) && $ans->header->ancount > 0) {
It should say:
if (is_object($ans) && ($ans->header->ancount > 0 || $ans->header->nscount > 0 )) {
As you can see by using dig, answer is 0 but authority is 2, which translates to ancount being 0 but nscount being 2. So only checking ancount will give a failed query but also checking nscount gives a succesful query.
$ dig @ns1.nic.uk -t ns cocacola.co.uk
; <<>> DiG 9.2.1 <<>> @ns1.nic.uk -t ns cocacola.co.uk
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57031
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 2, ADDITIONAL: 2
;; QUESTION SECTION:
;cocacola.co.uk. IN NS
;; AUTHORITY SECTION:
cocacola.co.uk. 172800 IN NS ns.coca-cola.co.uk.
cocacola.co.uk. 172800 IN NS ns2.coca-cola.co.uk.
;; ADDITIONAL SECTION:
ns.coca-cola.co.uk. 172800 IN A 217.199.173.167
ns2.coca-cola.co.uk. 172800 IN A 217.199.173.168
;; Query time: 77 msec
;; SERVER: 195.66.240.130#53(ns1.nic.uk)
;; WHEN: Mon Apr 4 12:25:57 2005
;; MSG SIZE rcvd: 109
[2005-04-06 15:06 UTC] cox at idecnet dot com
Just a note: this bug is also present in perl Net::DNS