From: Kees Monshouwer Date: Mon, 20 Apr 2015 18:18:22 +0000 (+0200) Subject: fix pointers pointing to pointers in dnsname X-Git-Tag: dnsdist-1.0.0-alpha1~248^2~88^2~9^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3082637925c0647f29b8b69b65a9e2ecce8d5b6d;p=pdns fix pointers pointing to pointers in dnsname --- diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index 26c54fdc3..8f1bb5b0f 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -26,7 +26,6 @@ DNSName::DNSName(const char* pos, int len, int offset, bool uncompress, uint16_t // this should be the __only__ dns name parser in PowerDNS. void DNSName::packetParser(const char* pos, int len, int offset, bool uncompress, uint16_t* qtype, uint16_t* qclass, unsigned int* consumed) { - bool labelAdded = false; unsigned char labellen; const char *opos = pos; pos += offset; @@ -39,15 +38,14 @@ void DNSName::packetParser(const char* pos, int len, int offset, bool uncompress labellen &= (~0xc0); int newpos = (labellen << 8) + *(const unsigned char*)pos; - if(newpos < len) - packetParser(opos, len, newpos, labelAdded); + if(newpos < offset) + packetParser(opos, len, newpos, true); else - throw std::range_error("Found an invalid compression pointer"); + throw std::range_error("Found a forward reference during label decompression"); pos++; break; } if (pos + labellen < end) { - labelAdded = true; appendRawLabel(string(pos, labellen)); } else diff --git a/pdns/test-dnsname_cc.cc b/pdns/test-dnsname_cc.cc index f48f5e26d..547ab3238 100644 --- a/pdns/test-dnsname_cc.cc +++ b/pdns/test-dnsname_cc.cc @@ -381,6 +381,14 @@ BOOST_AUTO_TEST_CASE(test_compression) { // Compression test BOOST_CHECK_EQUAL(dn.toString(), "www.example.com."); } +BOOST_AUTO_TEST_CASE(test_pointer_pointer_root) { // Pointer to pointer to root + + string name("\x00""\xc0""\x00""\x03""com\xc0""\x01",9); + + DNSName dn(name.c_str(), name.size(), 3, true); + BOOST_CHECK_EQUAL(dn.toString(), "com."); +} + BOOST_AUTO_TEST_CASE(test_bad_compression_pointer) { // Pointing beyond packet boundary std::string name("\x03""com\x00""\x07""example\xc0""\x11""xc0""\x00", 17);