Subject: | Net::DNS::Nameserver dies on invalid packets |
Using Net::DNS::Nameserver version 835 (from Net::DNS 0.66), if you send
an invalid packet to it using:
use IO::Socket::INET;
my $sock = new IO::Socket::INET(
PeerAddr => $dns_server,
PeerPort => 53,
Proto => 'udp',
Timeout => 1
);
print $sock "foo";
the nameserver dies with:
Can't call method "additional" on an undefined value at
/usr/local/lib/perl/5.8.8/Net/DNS/Nameserver.pm line 387.
A fix is below:
@@ -366,9 +366,11 @@
peerport => $sock->peerport
};
my $reply = $self->make_reply($query, $peerhost, $conn) ||
return;
- my $max_len = $self->max_udp_len($query);
- print "Maximum reply length as advertosed in EDNS from
$peerhost:$peerport: $max_len\n" if $self->{"Verbose"};
- $reply->truncate($max_len) if $self->{Truncate};
+ if ($query) {
+ my $max_len = $self->max_udp_len($query);
+ print "Maximum reply length as advertised in EDNS from
$peerhost:$peerport: $max_len\n" if $self->{"Verbose"};
+ $reply->truncate($max_len) if $self->{Truncate};
+ }
local $| = 1 if $self->{"Verbose"};
print "Writing response - " if $self->{"Verbose"};
The problem is calling $self->max_udp_len($query) when $query may be
undef if it's an invalid packet.
Marked as "critical" as you can easily DOS anything using
Net::DNS::Nameserver.