From 385a22085d5ddb119dad293c617716ab64fd7bad Mon Sep 17 00:00:00 2001 From: Kees Monshouwer Date: Thu, 13 Apr 2023 09:32:16 +0200 Subject: [PATCH] make getCommonLabels() root aware --- pdns/dnsname.cc | 6 +++++- pdns/dnssecsigner.cc | 3 --- pdns/test-dnsname_cc.cc | 12 ++++++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index 3bfbf3007f..25a90078a8 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -296,7 +296,11 @@ void DNSName::makeUsRelative(const DNSName& zone) DNSName DNSName::getCommonLabels(const DNSName& other) const { - DNSName result; + if (empty() || other.empty()) { + return DNSName(); + } + + DNSName result(g_rootdnsname); const std::vector ours = getRawLabels(); const std::vector others = other.getRawLabels(); diff --git a/pdns/dnssecsigner.cc b/pdns/dnssecsigner.cc index 7fd7d53253..74dc882ab0 100644 --- a/pdns/dnssecsigner.cc +++ b/pdns/dnssecsigner.cc @@ -226,9 +226,6 @@ void addRRSigs(DNSSECKeeper& dk, UeberBackend& db, const set& authSet, signQName = pos->dr.d_name.makeLowerCase(); if (pos->dr.d_type == QType::NSEC) { authQName = signQName.getCommonLabels(getRR(pos->dr)->d_next); - if (authQName.empty()) { - authQName = g_rootdnsname; - } } else { authQName = signQName; diff --git a/pdns/test-dnsname_cc.cc b/pdns/test-dnsname_cc.cc index 0001d1ee04..43c1b900dd 100644 --- a/pdns/test-dnsname_cc.cc +++ b/pdns/test-dnsname_cc.cc @@ -1019,14 +1019,18 @@ BOOST_AUTO_TEST_CASE(test_getcommonlabels) { BOOST_CHECK_EQUAL(name2.getCommonLabels(name1), DNSName("powerdns.com")); const DNSName name3("www.powerdns.org"); - BOOST_CHECK_EQUAL(name1.getCommonLabels(name3), DNSName()); - BOOST_CHECK_EQUAL(name2.getCommonLabels(name3), DNSName()); - BOOST_CHECK_EQUAL(name3.getCommonLabels(name1), DNSName()); - BOOST_CHECK_EQUAL(name3.getCommonLabels(name2), DNSName()); + BOOST_CHECK_EQUAL(name1.getCommonLabels(name3), g_rootdnsname); + BOOST_CHECK_EQUAL(name2.getCommonLabels(name3), g_rootdnsname); + BOOST_CHECK_EQUAL(name3.getCommonLabels(name1), g_rootdnsname); + BOOST_CHECK_EQUAL(name3.getCommonLabels(name2), g_rootdnsname); const DNSName name4("WWw.PowErDnS.org"); BOOST_CHECK_EQUAL(name3.getCommonLabels(name4), name3); BOOST_CHECK_EQUAL(name4.getCommonLabels(name3), name4); + + const DNSName(name5); + BOOST_CHECK_EQUAL(name1.getCommonLabels(name5), DNSName()); + BOOST_CHECK_EQUAL(name5.getCommonLabels(name1), DNSName()); } BOOST_AUTO_TEST_SUITE_END() -- 2.47.2