From: Remi Gacogne Date: Fri, 27 Oct 2017 12:06:29 +0000 (+0200) Subject: Fix case-sensitive comparison in DNSName::getCommonLabels() X-Git-Tag: rec-4.1.0-rc2~7^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=097f8a4207cbb38b40ea31e6208c95b9b1a6bcd0;p=pdns Fix case-sensitive comparison in DNSName::getCommonLabels() --- diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index feabbac7e..c9dee7770 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -261,11 +261,14 @@ DNSName DNSName::getCommonLabels(const DNSName& other) const const std::vector 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; diff --git a/pdns/test-dnsname_cc.cc b/pdns/test-dnsname_cc.cc index c95e8fde6..850b0963d 100644 --- a/pdns/test-dnsname_cc.cc +++ b/pdns/test-dnsname_cc.cc @@ -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()