From 0e8e76f7bf5f5788a1ed175789208a339113d22e Mon Sep 17 00:00:00 2001 From: Otto Date: Fri, 22 Oct 2021 11:19:59 +0200 Subject: [PATCH] Avoid Undefined Behaviour by making sure the packet size is at least the size passed in --- pdns/test-dnsname_cc.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pdns/test-dnsname_cc.cc b/pdns/test-dnsname_cc.cc index 6c88a8baaf..98aed701bf 100644 --- a/pdns/test-dnsname_cc.cc +++ b/pdns/test-dnsname_cc.cc @@ -388,28 +388,28 @@ BOOST_AUTO_TEST_CASE(test_hashContainer) { BOOST_AUTO_TEST_CASE(test_QuestionHash) { - vector packet; + vector packet(sizeof(dnsheader)); reportBasicTypes(); // A return init case BOOST_CHECK_EQUAL(hashQuestion(packet.data(), sizeof(dnsheader), 0xffU), 0xffU); // We subtract 4 from the packet sizes since DNSPacketWriter adds a type and a class - // W eexcpect the hash of the root to bne unequal to the burtle init value + // We expect the hash of the root to be unequal to the burtle init value DNSPacketWriter dpw0(packet, DNSName("."), QType::AAAA); BOOST_CHECK(hashQuestion(packet.data(), packet.size() - 4, 0xffU) != 0xffU); - // A truncated buffer + // A truncated buffer should return the init value DNSPacketWriter dpw1(packet, DNSName("."), QType::AAAA); BOOST_CHECK_EQUAL(hashQuestion(packet.data(), packet.size() - 5, 0xffU), 0xffU); DNSPacketWriter dpw2(packet, DNSName("www.ds9a.nl."), QType::AAAA); - // Let's make an invalid name by overwriting the length of the second label just outside + // Let's make an invalid name by overwriting the length of the second label just outside the buffer packet[sizeof(dnsheader) + 4] = 8; BOOST_CHECK_EQUAL(hashQuestion(packet.data(), packet.size() - 4, 0xffU), 0xffU); DNSPacketWriter dpw3(packet, DNSName("www.ds9a.nl."), QType::AAAA); - // Let's make an invalid name by overwriting the length of the second label way outside + // Let's make an invalid name by overwriting the length of the second label way outside the buffer packet[sizeof(dnsheader) + 4] = 0xff; BOOST_CHECK_EQUAL(hashQuestion(packet.data(), packet.size() - 4, 0xffU), 0xffU); -- 2.47.2