From 547d68ff19f082e7c986b34b04a6ea6ad605a62b 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. (cherry picked from commit ed221d0bc700158c21fcb8fc4463085713d07c53) --- 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 d6e6bb258f..e9adc82fb6 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -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)); diff --git a/pdns/test-dnsname_cc.cc b/pdns/test-dnsname_cc.cc index 328e3a928d..0015972f7a 100644 --- a/pdns/test-dnsname_cc.cc +++ b/pdns/test-dnsname_cc.cc @@ -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)); } -- 2.47.2