From: php at ter dot dk
Operating system: Linux 2.4 debian sarge
PHP version: 5.1.0RC3
PHP Bug Type: Network related
Bug description: dns_get_record() returns strange results for MX for long hostnames
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
}
--
Edit bug report at http://bugs.php.net/?id=34938&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=34938&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=34938&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=34938&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=34938&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=34938&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=34938&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=34938&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=34938&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=34938&r=support
Expected behavior: http://bugs.php.net/fix.php?id=34938&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=34938&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=34938&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=34938&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=34938&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=34938&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=34938&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=34938&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=34938&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=34938&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=34938&r=mysqlcfg