From: Otto Date: Fri, 22 Oct 2021 09:19:59 +0000 (+0200) Subject: Avoid Undefined Behaviour by making sure the packet size is at least X-Git-Tag: rec-4.6.0-beta1~45^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F10872%2Fhead;p=thirdparty%2Fpdns.git Avoid Undefined Behaviour by making sure the packet size is at least the size passed in --- 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);