Subject: | Net::DNS::Packet->data makes incorrect assumptions |
Summary:
Is currently impossible to generate packets via N:D:P methods which do
not have a question section. Having code do '@{$pktobj->{"question"}} =
();' is not portable to future versions of Net::DNS .
Specifics and Patches:
Net::DNS::Packet->pop (v 102 from Net::DNS 0.48)
The pop method does not let you remove question records from the packet.
Patch:
608a627,632
Show quoted text
> } elsif ($section eq "question") {
> my $qdcount = $self->{"question"}->qdcount;
> if ($qdcount) {
> $rr = pop @{$self->{"question"}};
> $self->{"header"}->qrcount($qdcount - 1);
> }
Net::DNS::Packet->data (same version)
There is no check that the number of records alleged to be output (header->??count) matches the number of records actually output. This
can cause errors later when parsing the output of ->data by other programs.
Patch:
263c263,269
< my $data = $self->{"header"}->data;
---
Show quoted text> # Collect the data first, and count the number of records along
> # the way.
> my $qdcount = 0;
> my $ancount = 0;
> my $nscount = 0;
> my $arcount = 0;
> my $data = undef;
266a273
Show quoted text> $qdcount++;
270a278
Show quoted text> $ancount++;
274a283
Show quoted text> $nscount++;
278a288
Show quoted text> $arcount++;
281c291,299
< return $data;
---
Show quoted text> # Fix up the header so the counts are correct. This overwrites
> # the user's settings, but the user should know what they aredoing.
> $self->{"header"}->qdcount( $qdcount );
> $self->{"header"}->ancount( $ancount );
> $self->{"header"}->nscount( $nscount );
> $self->{"header"}->arcount( $arcount );
>
> # Return the header and everything else.
> return $self->{"header"}->data . $data;
--==--
Bruce.