]> granicus.if.org Git - pdns/commitdiff
fix for root in DNSName isParent() and some tests
authorKees Monshouwer <mind04@monshouwer.org>
Wed, 11 Mar 2015 13:32:56 +0000 (14:32 +0100)
committermind04 <mind04@monshouwer.org>
Wed, 11 Mar 2015 15:32:44 +0000 (16:32 +0100)
pdns/dnsname.cc
pdns/test-dnsname_cc.cc

index 78df576b859a90a7c747f924f7342d875ad7191d..3dc80111062021bd6a49862ecf1e1adf1170ebcd 100644 (file)
@@ -75,18 +75,20 @@ std::string DNSName::toDNSString() const
 // are WE part of parent
 bool DNSName::isPartOf(const DNSName& parent) const
 {
-  if(parent.d_storage.size() > d_storage.size()) 
+  if(parent.d_storage.empty())
+    return true;
+  if(parent.d_storage.size() > d_storage.size())
     return false;
 
   // this is slightly complicated since we can't start from the end, since we can't see where a label begins/ends then
   for(auto us=d_storage.cbegin(); us<d_storage.cend() && d_storage.cend()-us >= (unsigned int)parent.d_storage.size(); us+=*us+1) {
     if (d_storage.cend()-us == (unsigned int)parent.d_storage.size()) {
       auto p = parent.d_storage.cbegin();
-      for(; us != d_storage.cend() && p != parent.d_storage.cend(); ++us, ++p) {
+      for(; us != d_storage.cend(); ++us, ++p) {
         if(tolower(*p) != tolower(*us))
-          break;
+          return false;
       }
-      return (p==parent.d_storage.end());
+      return true;
     }
   }
   return false;
index f1122e006927304006eee5d9a1f68c1c3419c8a3..e15a5e84c1197426904f4c89e0f28a1635b63cde 100644 (file)
@@ -35,6 +35,50 @@ BOOST_AUTO_TEST_CASE(test_basic) {
 
   BOOST_CHECK(DNSName("www.ds9a.nl.").toString() == "www.ds9a.nl.");
 
+
+  { // Check root part of root
+    DNSName name;
+    DNSName parent;
+    BOOST_CHECK(name.isPartOf(parent));
+  }
+
+  { // Check name part of root
+    DNSName name("a.");
+    DNSName parent;
+    BOOST_CHECK(name.isPartOf(parent));
+  }
+
+  { // Label boundary
+    DNSName name("a\002bb.");
+    DNSName parent("bb.");
+    BOOST_CHECK(!name.isPartOf(parent));
+  }
+
+  { // Multi label parent
+    DNSName name("a.bb.ccc.dddd.");
+    DNSName parent("ccc.dddd.");
+    BOOST_CHECK(name.isPartOf(parent));
+  }
+
+  { // Last char diff
+    DNSName name("a.bb.ccc.dddd.");
+    DNSName parent("ccc.dddx.");
+    BOOST_CHECK(!name.isPartOf(parent));
+  }
+
+  { // Equal length identical
+    DNSName name("aaaa.bbb.cc.d.");
+    DNSName parent("aaaa.bbb.cc.d.");
+    BOOST_CHECK(name.isPartOf(parent));
+  }
+
+  { // Equal length first char diff
+    DNSName name("xaaa.bbb.cc.d.");
+    DNSName parent("aaaa.bbb.cc.d.");
+    BOOST_CHECK(!name.isPartOf(parent));
+  }
+
+
   DNSName left("ds9a.nl.");
   left.prependRawLabel("www");
   BOOST_CHECK( left == DNSName("WwW.Ds9A.Nl."));