summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc van der Wal <marc.vanderwal@afnic.fr>2022-09-01 10:21:23 +0200
committerMarc van der Wal <marc.vanderwal@afnic.fr>2022-09-01 16:20:52 +0200
commit945db0e12e33bc2e3157ee553c58f96431ea21ec (patch)
tree9a051283142770d1ad8bef98bb02ea5110c9923b
parentfb6c9ff85a51bb026dc3073695df6eddc2a0bfde (diff)
Add unit tests to reproduce issue on bad CAA RRs
Add a unit test in packet.t and another one in rr.t to reproduce the segfaults I observed. See also issue #149.
-rw-r--r--t/packet.t31
-rw-r--r--t/rr.t8
2 files changed, 39 insertions, 0 deletions
diff --git a/t/packet.t b/t/packet.t
index 0d55feb..8be8565 100644
--- a/t/packet.t
+++ b/t/packet.t
@@ -28,4 +28,35 @@ is($p->answerfrom, undef, 'No answerfrom');
$p->answerfrom('127.0.0.1');
is($p->answerfrom, '127.0.0.1', 'Localhost');
+subtest "croak when stringifying packet with malformed CAA" => sub {
+ my $will_croak = sub {
+ # Constructing a synthetic packet that would have the following string
+ # representation in dig-like format:
+ #
+ # ;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 13944
+ # ;; flags: qr aa ; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
+ # ;; QUESTION SECTION:
+ # ;; bad-caa.example. IN CAA
+ #
+ # ;; ANSWER SECTION:
+ # bad-caa.example. 3600 IN CAA \# 4 C0000202
+ #
+ # ;; AUTHORITY SECTION:
+ #
+ # ;; ADDITIONAL SECTION:
+ my $packet_bin = pack(
+ 'H*',
+ '367884000001000100000000' . # header
+ '076261642d636161076578616d706c650001010001' . # question
+ 'c00c0101000100000e100004c0000202' # bad answer
+ );
+
+ my $packet = Zonemaster::LDNS::Packet->new_from_wireformat( $packet_bin );
+
+ # This must croak
+ $packet->string;
+ };
+ like( exception { $will_croak->() }, qr/^Failed to convert packet to string/ );
+};
+
done_testing();
diff --git a/t/rr.t b/t/rr.t
index 9b7aa66..f9f0403 100644
--- a/t/rr.t
+++ b/t/rr.t
@@ -226,4 +226,12 @@ subtest 'SPF' => sub {
is( $spf->spfdata, '"v=spf1 ip4:85.30.129.185/24 mx:mail.frobbit.se ip6:2a02:80:3ffe::0/64 ~all"' );
};
+subtest 'croak when given malformed CAA records' => sub {
+ my $will_croak = sub {
+ Zonemaster::LDNS::RR->new(
+ 'bad-caa.example. 3600 IN CAA \# 4 C0000202' )
+ };
+ like( exception { $will_croak->() }, qr/^Failed to convert RR to string/ );
+};
+
done_testing;