From ed221d0bc700158c21fcb8fc4463085713d07c53 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 12 Dec 2016 17:16:11 +0100 Subject: [PATCH] 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. --- pdns/dnsname.hh | 7 ++++++- pdns/test-dnsname_cc.cc | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index 47f33a0ebb..fecff61f9e 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 2622302d96..5e6c5041c4 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)); } -- 2.47.2