From 326ba6a5b0c17729b55b15fef9a677ab3b891045 Mon Sep 17 00:00:00 2001 From: James Coglan Date: Mon, 10 Jun 2024 14:46:55 +0100 Subject: [PATCH] resolved: tests for dns_packet_extract(); check handling of self-referential compression pointers --- src/resolve/test-dns-packet-extract.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/resolve/test-dns-packet-extract.c b/src/resolve/test-dns-packet-extract.c index 0b7f9e45a46..14de04b806a 100644 --- a/src/resolve/test-dns-packet-extract.c +++ b/src/resolve/test-dns-packet-extract.c @@ -935,6 +935,30 @@ TEST(packet_query_bad_compression_5) { ASSERT_EQ(dns_answer_size(packet->answer), 0u); } +TEST(packet_query_bad_compression_6) { + _cleanup_(dns_packet_unrefp) DnsPacket *packet = NULL; + + ASSERT_OK(dns_packet_new(&packet, DNS_PROTOCOL_DNS, 0, DNS_PACKET_SIZE_MAX)); + ASSERT_NOT_NULL(packet); + dns_packet_truncate(packet, 0); + + const uint8_t data[] = { + 0x00, 0x2a, 0x01, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + /* name */ 0x03, 'w', 'w', 'w', + 0xc0, 0x0c, /* points at the current name */ + /* A */ 0x00, 0x01, + /* IN */ 0x00, 0x01 + }; + + ASSERT_OK(dns_packet_append_blob(packet, data, sizeof(data), NULL)); + + ASSERT_ERROR(dns_packet_extract(packet), EBADMSG); + ASSERT_EQ(dns_question_size(packet->question), 0u); + ASSERT_EQ(dns_answer_size(packet->answer), 0u); +} + /* ================================================================ * reply: A * ================================================================ */ -- 2.47.3