]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
make getCommonLabels() root aware 12740/head
authorKees Monshouwer <mind04@monshouwer.org>
Thu, 13 Apr 2023 07:32:16 +0000 (09:32 +0200)
committermind04 <mind04@monshouwer.org>
Thu, 13 Apr 2023 11:10:11 +0000 (13:10 +0200)
pdns/dnsname.cc
pdns/dnssecsigner.cc
pdns/test-dnsname_cc.cc

index 3bfbf3007fbd4dc4f037ab557c17e9fe4e41020c..25a90078a89081922ed3ca1458a358532db66faa 100644 (file)
@@ -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<std::string> ours = getRawLabels();
   const std::vector<std::string> others = other.getRawLabels();
index 7fd7d532532b208207feb2c932817e159a437318..74dc882ab012fffdcdf4301d58f912f6cc06b46b 100644 (file)
@@ -226,9 +226,6 @@ void addRRSigs(DNSSECKeeper& dk, UeberBackend& db, const set<DNSName>& authSet,
     signQName = pos->dr.d_name.makeLowerCase();
     if (pos->dr.d_type == QType::NSEC) {
       authQName = signQName.getCommonLabels(getRR<NSECRecordContent>(pos->dr)->d_next);
-      if (authQName.empty()) {
-        authQName = g_rootdnsname;
-      }
     }
     else {
       authQName = signQName;
index 0001d1ee04f6fe4618f8ace6cd1317ff6de68fa6..43c1b900ddf649ced32610b3e02cf31ba71d130b 100644 (file)
@@ -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()