From f867aa74ee518bdefe07ce9c5ed7e0a1b9dfbd1e Mon Sep 17 00:00:00 2001 From: bert hubert Date: Thu, 5 Nov 2015 16:13:50 +0100 Subject: [PATCH] test parsing the root from packets, fix that we failed on that --- pdns/dnsname.cc | 2 ++ pdns/test-dnsname_cc.cc | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index 8388391d4..4d17129f7 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -66,6 +66,8 @@ void DNSName::packetParser(const char* pos, int len, int offset, bool uncompress throw std::range_error("Found an invalid label length in qname"); pos+=labellen; } + if(d_storage.empty()) + d_storage.append(1, (char)0); // we just parsed the root if(consumed) *consumed = pos - opos - offset; if(qtype && pos + labellen + 2 <= end) diff --git a/pdns/test-dnsname_cc.cc b/pdns/test-dnsname_cc.cc index f102b45a2..c0b12f5e9 100644 --- a/pdns/test-dnsname_cc.cc +++ b/pdns/test-dnsname_cc.cc @@ -230,6 +230,16 @@ BOOST_AUTO_TEST_CASE(test_Append) { BOOST_CHECK(dn == DNSName("www.powerdns.com.")); } +BOOST_AUTO_TEST_CASE(test_PacketParse) { + vector packet; + reportBasicTypes(); + DNSName root("."); + DNSPacketWriter dpw1(packet, DNSName("."), QType::AAAA); + DNSName p((char*)&packet[0], packet.size(), 12, false); + BOOST_CHECK_EQUAL(p, root); +} + + BOOST_AUTO_TEST_CASE(test_QuestionHash) { vector packet; reportBasicTypes(); -- 2.40.0