From: Kees Monshouwer Date: Thu, 13 Apr 2023 07:32:16 +0000 (+0200) Subject: make getCommonLabels() root aware X-Git-Tag: auth-4.8.0-beta1~8^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F12740%2Fhead;p=thirdparty%2Fpdns.git make getCommonLabels() root aware --- 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()