Skip to content

Commit

Permalink
Add minimum value check for edns_size parameter in Zonemaster::Engine…
Browse files Browse the repository at this point in the history
…::Nameserver->query()

This parameter, set either by "edns_size" or "edns_details->size", is an unsigned 16-bit value,
thus the minimum value should be 0. Documentation and unit tests are updated too.
  • Loading branch information
tgreenx committed Nov 21, 2024
1 parent fbc7570 commit f4ea247
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/Zonemaster/Engine/Nameserver.pm
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ sub query {
$edns_size = $href->{edns_details}{size} // ( $href->{edns_size} // ( $dnssec ? $UDP_DNSSEC_QUERY_DEFAULT : $UDP_EDNS_QUERY_DEFAULT ) );
}

croak "edns_size (or edns_details->size) parameter cannot exceed 65535" if $edns_size > 65535;
croak "edns_size (or edns_details->size) parameter must be a value between 0 and 65535" if $edns_size > 65535 or $edns_size < 0;

$md5->add( q{EDNS_UDP_SIZE} , $edns_size );

Expand Down Expand Up @@ -823,8 +823,8 @@ If set to true, prevents a server to be black-listed on a query in case there is
=item edns_size
Set the EDNS0 UDP maximum size. Defaults to 0, or 512 if the query is a non-DNSSEC EDNS query,
or 1232 if the query is a DNSSEC query. Cannot be set higher than 65535.
Set the EDNS0 UDP maximum size. The value must be comprised between 0 and 65535.
Defaults to 0, or 512 if the query is a non-DNSSEC EDNS query, or 1232 if the query is a DNSSEC query.
Setting a value other than 0 will also implicitly enable EDNS for the query.
Value overridden by C<edns_details-E<gt>{size}> (if also given). More details in L<edns_details> below.
Expand Down
2 changes: 2 additions & 0 deletions t/nameserver.t
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ subtest 'dnssec, edns_size and edns_details{do, size} flags behavior for queries

dies_ok { $p = $ns->query( 'fr', 'SOA', { "edns_size" => 65536 } ); } "dies when edns_size exceeds 65535";
dies_ok { $p = $ns->query( 'fr', 'SOA', { "edns_details" => { "size" => 65536 } } ); } "dies when edns_size (set with edns_details->size) exceeds 65535";
dies_ok { $p = $ns->query( 'fr', 'SOA', { "edns_size" => -1 } ); } "dies when edns_size is lower than 0";
dies_ok { $p = $ns->query( 'fr', 'SOA', { "edns_details" => { "size" => -1 } } ); } "dies when edns_size (set with edns_details->size) is lower than 0";
};

if ( $ENV{ZONEMASTER_RECORD} ) {
Expand Down

0 comments on commit f4ea247

Please sign in to comment.