|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47035 dns_get_record returns a garbage byte at the end of a TXT record
Submitted: 2009-01-08 09:07 UTC Modified: 2009-01-15 12:44 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: valli at icsurselva dot ch Assigned: felipe (profile)
Status: Closed Package: Network related
PHP Version: 5.2.8 OS: gentoo
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: valli at icsurselva dot ch
New email:
PHP Version: OS:


 [2009-01-08 09:07 UTC] valli at icsurselva dot ch
The last byte of a TXT record returned by dns_get_record
is garbage.

Reproduce code:
$rt = dns_get_record('', DNS_TXT);
$txt = $rt[0]['txt'];
print $txt." (".strlen($txt).")\n";
foreach(str_split($txt) as $char) {
    print "$char\t".ord($char)."\n";

Expected result:
ch (2)
c       99
h       104

Actual result:
ch (3)
c       99
h       104


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-08 09:31 UTC] valli at icsurselva dot ch
Here's my current workaround:

$rt = @dns_get_record($lookuphost, DNS_ANY);
// workaround for
if (substr(PHP_VERSION,0,strpos(PHP_VERSION, '-')) == '5.2.8') {
    for($i = 0, $rts = sizeof($rt); $i < $rts; ++$i) {
        if ($rt[$i]['type'] == 'TXT') {
            // remove last byte
            $rt[$i]['txt'] = substr($rt[$i]['txt'], 0, -1);
 [2009-01-08 17:20 UTC]
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
Thank you for the report, and for helping us make PHP better.

 [2009-01-09 11:36 UTC] valli at icsurselva dot ch
Hello again,
I just dicovered that the garbage chars not
only appear at the end of a TXT record.
 nslookup -type=TXT
 Returns: text = "13237 3303 44038" "" "17"

This DNS request returns 3 Strings.
If I do this with dns_get_record the strings are concatenated
(containing a garbage char between the strings)

BTW: Is it really a good idea to concatenate this strings?
     Wouldn't it better to return a array containing this strings?
     Example: the anwers from are really
              hard (if not impossible) to parse in this way:
              "13237 3303 44038195.186.0.017"
              it would be better in this way:
              array("13237 3303 44038","","17")
 [2009-01-09 12:52 UTC]
I agree, it would be more logical to return an array of strings.

 [2009-01-12 20:40 UTC]
Sure, it's right to do.

We add a new entry in the array returned, on 5.3+ we get:

array(6) {
  string(35) ""
  string(3) "TXT"
  string(31) "13237 3303 44038195.186.0.017"
  array(3) {
    string(16) "13237 3303 44038"
    string(11) ""
    string(2) "17"
  string(2) "IN"

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Jan 30 18:05:56 2023 UTC