PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Networking » Net_DNS » Bug #4999

Mishandling of TXT record data

Details

Submitted2005-08-04 18:26 UTC
Fromrdalverny at mandriva dot com
Assignedbate
StatusNo Feedback
PackageNet_DNS
PHP VersionIrrelevant
OSLinux
Roadmaps(Not assigned)

Comments

[2005-08-04 18:26 UTC] rdalverny at mandriva dot com

Description:
------------
Using Net_DNS 1.0.0rc1.

Text data seems to mishandled when querying and updating a nameserver.

I encountered the problem when trying to update a DNS record, and found that the handling of the text data did not work properly when fetching records as well.

I rewrote parts of the Net_DNS_RR_TXT class after the Perl Net::DNS relative class.

It seems to work, but it all comes down to having a working shellwords() equivalent function in PHP, which I could not do at this time.

Here is the rewritten class:
http://people.mandriva.com/~rdalverny/tmp/Net_DNS_RR_TXT.phps

Test script:
---------------
Here is a sample zone:

$ORIGIN example.com.
host TXT "hello"
TXT "hello" "world" "?"
TXT "hello world"
TXT "hello" "world" "hey you"

Expected result:
----------------
$ dig -t TXT host.example.com

;; QUESTION SECTION:
;host.example.com. IN TXT

;; ANSWER SECTION:
host.example.com. 3600 IN TXT "hello"
host.example.com. 3600 IN TXT "hello" "world"
host.example.com. 3600 IN TXT "hello world"
host.example.com. 3600 IN TXT "hello" "world" "hey you"

Actual result:
--------------
Querying with Net_DNS returns this:

;; QUESTION SECTION:
;host.example.com. IN TXT

;; ANSWER SECTION:
host.example.com. 3600 IN TXT "hello"
host.example.com. 3600 IN TXT "hello"
host.example.com. 3600 IN TXT "hello world"
host.example.com. 3600 IN TXT "hello"

[2005-11-29 01:13 UTC] fa at art-core dot org

I haven't yet got afull grasp on it, but as it seems to me,
object(net_dns_rr_txt)(8) { ["text"] } is always set to NULL and instead ["char_str_list"] is used, doesn't this break BC?

Also ["rdata"] in the unpatched version holds the content of all TXT fields in a form like
["rdata"]=>
string(17) ".das.ist.ein.test"
["text"]=>
string(3) "das"
- can't this be stripped of . and be used instead?

And I'm undecided on the shellwords thing. A quick google search for shellwords only shows the perl/python/ruby implementations and no real usage.

[2005-11-29 13:25 UTC] rdalverny at mandriva dot com

I found an other way to solve it. Below is a diff for the Net/DNS/RR/TXT.php file.

It actually stores a string _or_ an array of strings in the text member of the class. Method rdatastr() is then updated to handle it. Maybe should we put it as an array all the time?

At least this returns what is expected.

[romain@zeb pear]# diff Net/DNS/RR/TXT.php /home/romain/TXT.php
50c50
<
---
> $maxoffset = $this->rdlength + $offset;
53,55c53,56
< list($text, $offset) = Net_DNS_Packet::label_extract($data, $offset);
<
< $this->text = $text;
---
> while( $maxoffset > $offset ) {
> list($text, $offset) = Net_DNS_Packet::label_extract($data, $offset);
> $this->text[] = $text;
> }
67a69
> print_r($this->text);
75c77,85
< return('"' . addslashes($this->text) . '"');
---
> if( is_array( $this->text ) ) {
> $tmp = '';
> foreach( $this->text as $t ) {
> $tmp[] = '"'.addslashes($t).'"';
> }
> return implode(' ',$tmp);
> } else {
> return('"' . addslashes($this->text) . '"');
> }

[2005-11-29 13:36 UTC] rdalverny at mandriva dot com

I forgot to mention it: this diff applies to the current 1.0.0rc1 Net/DNS/RR/TXT.php file, of course.

And I forgot a print_r() in the code, by the way.