Permalink
Browse files

SuffixMatchNode: Fix insertion issue for an existing node

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 ed221d0)
  • Loading branch information...
rgacogne authored and pieterlexis committed Dec 12, 2016
1 parent a08b422 commit 547d68ff19f082e7c986b34b04a6ea6ad605a62b
Showing with 13 additions and 1 deletion.
  1. +6 −1 pdns/dnsname.hh
  2. +7 −0 pdns/test-dnsname_cc.cc
View
@@ -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));
View
@@ -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));
}

0 comments on commit 547d68f

Please sign in to comment.