From 097f8a4207cbb38b40ea31e6208c95b9b1a6bcd0 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 27 Oct 2017 14:06:29 +0200 Subject: [PATCH] Fix case-sensitive comparison in DNSName::getCommonLabels() --- pdns/dnsname.cc | 7 +++++-- pdns/test-dnsname_cc.cc | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) 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() -- 2.50.1