]> granicus.if.org Git - pdns/commitdiff
SuffixMatchNode: Fix insertion issue for an existing node
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 12 Dec 2016 16:16:11 +0000 (17:16 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Tue, 14 Feb 2017 13:08:02 +0000 (14:08 +0100)
If the node we are about to insert already existed as an intermediary
one, we need to mark it as an end node.

(cherry picked from commit ed221d0bc700158c21fcb8fc4463085713d07c53)

pdns/dnsname.hh
pdns/test-dnsname_cc.cc

index d6e6bb258f4d5e66f19435e8bd97a3be5b79655d..e9adc82fb63dc2c7eada67794b73970919a677e7 100644 (file)
@@ -254,7 +254,12 @@ struct SuffixMatchNode
       endNode=true;
     }
     else if(labels.size()==1) {
-      children.insert(SuffixMatchNode(*labels.begin(), true));
+      auto res=children.insert(SuffixMatchNode(*labels.begin(), true));
+      if(!res.second) {
+        if(!res.first->endNode) {
+          res.first->endNode = true;
+        }
+      }
     }
     else {
       auto res=children.insert(SuffixMatchNode(*labels.rbegin(), false));
index 328e3a928d6ffae218bcdea8e8e8f233575f77f1..0015972f7a6b506efd63217140300cc67b164186 100644 (file)
@@ -427,6 +427,13 @@ BOOST_AUTO_TEST_CASE(test_suffixmatch) {
 
   smn.add(DNSName(".")); // block the root
   BOOST_CHECK(smn.check(DNSName("a.root-servers.net.")));
+
+  DNSName examplenet("example.net.");
+  DNSName net("net.");
+  smn.add(examplenet);
+  smn.add(net);
+  BOOST_CHECK(smn.check(examplenet));
+  BOOST_CHECK(smn.check(net));
 }