]> granicus.if.org Git - pdns/commitdiff
fix pointers pointing to pointers in dnsname
authorKees Monshouwer <mind04@monshouwer.org>
Mon, 20 Apr 2015 18:18:22 +0000 (20:18 +0200)
committermind04 <mind04@monshouwer.org>
Mon, 20 Apr 2015 18:33:12 +0000 (20:33 +0200)
pdns/dnsname.cc
pdns/test-dnsname_cc.cc

index 26c54fdc3166a4d66eac0067a436c198e032beee..8f1bb5b0f52b62dc3176dd95d7b0417f1a1ed90f 100644 (file)
@@ -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
index f48f5e26da8f5ac368bd5ad768bd625340ab5f12..547ab32385b8fa33d640841758a7a68fac552f17 100644 (file)
@@ -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);