From: bert hubert Date: Thu, 5 Nov 2015 15:13:50 +0000 (+0100) Subject: test parsing the root from packets, fix that we failed on that X-Git-Tag: dnsdist-1.0.0-alpha1~239^2~16 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f867aa74ee518bdefe07ce9c5ed7e0a1b9dfbd1e;p=pdns test parsing the root from packets, fix that we failed on that --- 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();