]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Fix case-sensitive comparison in DNSName::getCommonLabels() 5868/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 27 Oct 2017 12:06:29 +0000 (14:06 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 27 Oct 2017 12:06:29 +0000 (14:06 +0200)
pdns/dnsname.cc
pdns/test-dnsname_cc.cc

index feabbac7edfd79156456d60447b575aac0028b4a..c9dee777048ce09c761fdbd59706373d5e34b9cd 100644 (file)
@@ -261,11 +261,14 @@ DNSName DNSName::getCommonLabels(const DNSName& other) const
   const std::vector<std::string> others = other.getRawLabels();
 
   for (size_t pos = 0; ours.size() > pos && others.size() > pos; pos++) {
-    if (ours.at(ours.size() - pos - 1) != others.at(others.size() - pos - 1)) {
+    const std::string& ourLabel = ours.at(ours.size() - pos - 1);
+    const std::string& otherLabel = others.at(others.size() - pos - 1);
+
+    if (!pdns_iequals(ourLabel, otherLabel)) {
       break;
     }
 
-    result.prependRawLabel(ours.at(ours.size() - pos - 1));
+    result.prependRawLabel(ourLabel);
   }
 
   return result;
index c95e8fde6bc08ced9b7e33dc348b202fe6373e7f..850b0963d0510df27bfe84b2a485b66bf02224d4 100644 (file)
@@ -884,6 +884,10 @@ BOOST_AUTO_TEST_CASE(test_getcommonlabels) {
   BOOST_CHECK_EQUAL(name2.getCommonLabels(name3), DNSName());
   BOOST_CHECK_EQUAL(name3.getCommonLabels(name1), DNSName());
   BOOST_CHECK_EQUAL(name3.getCommonLabels(name2), DNSName());
+
+  const DNSName name4("WWw.PowErDnS.org");
+  BOOST_CHECK_EQUAL(name3.getCommonLabels(name4), name3);
+  BOOST_CHECK_EQUAL(name4.getCommonLabels(name3), name4);
 }
 
 BOOST_AUTO_TEST_SUITE_END()