From: Remi Gacogne Date: Mon, 12 Dec 2016 16:16:11 +0000 (+0100) Subject: SuffixMatchNode: Fix insertion issue for an existing node X-Git-Tag: dnsdist-1.1.0~1^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ed221d0bc700158c21fcb8fc4463085713d07c53;p=pdns 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. --- diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index 47f33a0eb..fecff61f9 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -256,7 +256,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)); diff --git a/pdns/test-dnsname_cc.cc b/pdns/test-dnsname_cc.cc index 2622302d9..5e6c5041c 100644 --- a/pdns/test-dnsname_cc.cc +++ b/pdns/test-dnsname_cc.cc @@ -491,6 +491,13 @@ BOOST_AUTO_TEST_CASE(test_suffixmatch) { smn.add(g_rootdnsname); // 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)); }