php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34938 dns_get_record() returns strange results for long hostnames
Submitted: 2005-10-21 05:08 UTC Modified: 2005-10-25 10:20 UTC
From: php at ter dot dk Assigned: tony2001 (profile)
Status: Closed Package: Network related
PHP Version: 5.1.0RC3 OS: Linux 2.4 debian sarge
Private report: No CVE-ID: None
 [2005-10-21 05:08 UTC] php at ter dot dk
Description:
------------
(the error also occurs in PHP5.0.5)

dns_get_record() results in strange behaviour when supplied with long hostnames, e.g.:

$ host -t mx 0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0.dk
0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0.dk      MX     10 mail.0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0.dk

.. but:

$ php -v
PHP 5.0.5-1.dotdeb.1 (cli) (built: Sep  7 2005 10:07:31)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.5, Copyright (c) 1998-2004 Zend Technologies

$ php -r 'var_dump(dns_get_record("0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0.dk",DNS_MX));'
array(0) {
}

$ ~/dev/php-5.1.0RC3/sapi/cli/php -v
PHP 5.1.0RC3 (cli) (built: Oct 21 2005 04:40:34)
Copyright (c) 1997-2005 The PHP Group
Zend Engine v2.1.0-dev, Copyright (c) 1998-2005 Zend Technologies

$ ~/dev/php-5.1.0RC3/sapi/cli/php -r 'var_dump(dns_get_record("0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0.dk",DNS_MX));'
array(0) {
}

(yes, the domain name is valid and has a MX entry)

Furthermore, strange results arrive when dns_get_record() is called with long hostnames several times after a succesful lookup (for at shorter hostname). According to var_dump(), dns_get_record() loops between returning an array with an int, a recursive array and NULL.

The error is not restricted to DNS_MX - same result will show up for e.g. DNS_A and DNS_NS requests.

Before suspecting the output of dns_get_record() I was baffled when php actually segfaulted when beginning a foreach()-loop with the return value of dns_get_record(). I suppose it happened when foreach() was supplied with a recursion.


Reproduce code:
---------------
<?php
var_dump(dns_get_record("0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0.dk",DNS_MX));
var_dump(dns_get_record("0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0.dk",DNS_MX));
var_dump(dns_get_record("php.net",DNS_MX));
var_dump(dns_get_record("0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0.dk",DNS_MX));
var_dump(dns_get_record("0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0.dk",DNS_MX));
var_dump(dns_get_record("0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0.dk",DNS_MX));
var_dump(dns_get_record("0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0.dk",DNS_MX));
var_dump(dns_get_record("0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0.dk",DNS_MX));
var_dump(dns_get_record("0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0.dk",DNS_MX));
?>


Expected result:
----------------
array(1) {
  [0]=>
  array(6) {
    ["host"]=>
    string(7) "0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0.dk"
    ["type"]=>
    string(2) "MX"
    ["pri"]=>
    int(10)
    ["target"]=>
    string(12) "mail.0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0o0.dk"
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(127779)
  }
}

(a couple of times)

Actual result:
--------------
array(0) {
}
array(0) {
}
array(2) {
  [0]=>
  array(6) {
    ["host"]=>
    string(7) "php.net"
    ["type"]=>
    string(2) "MX"
    ["pri"]=>
    int(5)
    ["target"]=>
    string(12) "osu1.php.net"
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(63337)
  }
  [1]=>
  array(6) {
    ["host"]=>
    string(7) "php.net"
    ["type"]=>
    string(2) "MX"
    ["pri"]=>
    int(15)
    ["target"]=>
    string(15) "smtp.osuosl.org"
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(63337)
  }
}
array(1) {
  [0]=>
  int(16384)
}
array(1) {
  [0]=>
  array(1) {
    [0]=>
    *RECURSION*
  }
}
array(1) {
  [0]=>
  NULL
}
array(1) {
  [0]=>
  int(16384)
}
array(1) {
  [0]=>
  array(1) {
    [0]=>
    *RECURSION*
  }
}
array(1) {
  [0]=>
  NULL
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-21 05:14 UTC] php at ter dot dk
Please be aware of line breaks added by the bug system.
 [2005-10-23 20:35 UTC] tony2001@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2005-10-24 01:05 UTC] php at ter dot dk
I think we have a major regression in latest snaps (same result in php5-200510232030 and php5-200510232230) where the return values are pretty strange for any host checked, even short hosts, e.g.:

$ ~/dev/php5-200510232230/sapi/cli/php -r 'var_dump(dns_get_record("php.net",DNS_MX));'
array(1) {
  [0]=>
  array(6) {
    ["host"]=>
    string(7) "php.net"
    ["type"]=>
    string(2) "MX"
    ["pri"]=>
    int(19)
    ["target"]=>
    string(0) ""
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(65537)
  }
}

$ ~/dev/php5-200510232230/sapi/cli/php -r 'var_dump(dns_get_record("php.net",DNS_A));'
array(1) {
  [0]=>
  array(5) {
    ["host"]=>
    string(7) "php.net"
    ["type"]=>
    string(1) "A"
    ["ip"]=>
    string(10) "0.4.64.246"
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(65536)
  }
}

$ ~/dev/php5-200510232230/sapi/cli/php -r 'var_dump(dns_get_record("php.net",DNS_NS));'
array(4) {
  [0]=>
  array(5) {
    ["host"]=>
    string(7) "php.net"
    ["type"]=>
    string(2) "NS"
    ["target"]=>
    string(0) ""
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(65536)
  }
  [1]=>
  array(5) {
    ["host"]=>
    string(37) "\003ns2\007easydns\003com\000.php.net"
    ["type"]=>
    string(2) "NS"
    ["target"]=>
    string(0) ""
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(65536)
  }
  [2]=>
  array(5) {
    ["host"]=>
    string(20) "\003ns1\192).php.net"
    ["type"]=>
    string(2) "NS"
    ["target"]=>
    string(0) ""
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(65536)
  }
  [3]=>
  array(5) {
    ["host"]=>
    string(24) "\007remote1\192).php.net"
    ["type"]=>
    string(2) "NS"
    ["target"]=>
    string(0) ""
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(65536)
  }
}

It seems like there is some kind of offset error (e.g. octet 1 and 2 in the IP address for the A lookup is presented as octet 3 and 4)

On the lighter side the long hostnames behave in the new way as well.

I'm sorry if I'm just impatient.

- Peter Brodersen
 [2005-10-24 01:11 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip

Try next snapshot.
The snapshot you're trying doesn't include the patch yet.
 [2005-10-25 05:32 UTC] php at ter dot dk
Sorry, still no dice with latest snapshot; php5-200510250230:

$ ~/dev/php5-200510250230/sapi/cli/php -r 'var_dump(dns_get_record("php.net",DNS_NS));'
array(4) {
  [0]=>
  array(5) {
    ["host"]=>
    string(7) "php.net"
    ["type"]=>
    string(2) "NS"
    ["target"]=>
    string(0) ""
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(65536)
  }
  [1]=>
  array(5) {
    ["host"]=>
    string(37) "\003ns2\007easydns\003com\000.php.net"
    ["type"]=>
    string(2) "NS"
    ["target"]=>
    string(0) ""
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(65536)
  }
  [2]=>
  array(5) {
    ["host"]=>
    string(24) "\007remote1\192).php.net"
    ["type"]=>
    string(2) "NS"
    ["target"]=>
    string(0) ""
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(65536)
  }
  [3]=>
  array(5) {
    ["host"]=>
    string(20) "\003ns1\192).php.net"
    ["type"]=>
    string(2) "NS"
    ["target"]=>
    string(0) ""
    ["class"]=>
    string(2) "IN"
    ["ttl"]=>
    int(65536)
  }
}

- Peter Brodersen
 [2005-10-25 10:20 UTC] tony2001@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 02:01:28 2024 UTC