Skip to content

Commit

Permalink
Merge pull request #3 from mind04/dnsname
Browse files Browse the repository at this point in the history
fix for root in DNSName isParent() and some tests
  • Loading branch information
ahupowerdns committed Mar 11, 2015
2 parents 08199f7 + 9e98d92 commit 02a2b54
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pdns/dnsname.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,20 @@ std::string DNSName::toDNSString() const
// are WE part of parent
bool DNSName::isPartOf(const DNSName& parent) const
{
if(parent.d_storage.size() > d_storage.size())
if(parent.d_storage.empty())
return true;
if(parent.d_storage.size() > d_storage.size())
return false;

// this is slightly complicated since we can't start from the end, since we can't see where a label begins/ends then
for(auto us=d_storage.cbegin(); us<d_storage.cend() && d_storage.cend()-us >= (unsigned int)parent.d_storage.size(); us+=*us+1) {
if (d_storage.cend()-us == (unsigned int)parent.d_storage.size()) {
auto p = parent.d_storage.cbegin();
for(; us != d_storage.cend() && p != parent.d_storage.cend(); ++us, ++p) {
for(; us != d_storage.cend(); ++us, ++p) {
if(tolower(*p) != tolower(*us))
break;
return false;
}
return (p==parent.d_storage.end());
return true;
}
}
return false;
Expand Down
44 changes: 44 additions & 0 deletions pdns/test-dnsname_cc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,50 @@ BOOST_AUTO_TEST_CASE(test_basic) {

BOOST_CHECK(DNSName("www.ds9a.nl.").toString() == "www.ds9a.nl.");


{ // Check root part of root
DNSName name;
DNSName parent;
BOOST_CHECK(name.isPartOf(parent));
}

{ // Check name part of root
DNSName name("a.");
DNSName parent;
BOOST_CHECK(name.isPartOf(parent));
}

{ // Label boundary
DNSName name("a\002bb.");
DNSName parent("bb.");
BOOST_CHECK(!name.isPartOf(parent));
}

{ // Multi label parent
DNSName name("a.bb.ccc.dddd.");
DNSName parent("ccc.dddd.");
BOOST_CHECK(name.isPartOf(parent));
}

{ // Last char diff
DNSName name("a.bb.ccc.dddd.");
DNSName parent("ccc.dddx.");
BOOST_CHECK(!name.isPartOf(parent));
}

{ // Equal length identical
DNSName name("aaaa.bbb.cc.d.");
DNSName parent("aaaa.bbb.cc.d.");
BOOST_CHECK(name.isPartOf(parent));
}

{ // Equal length first char diff
DNSName name("xaaa.bbb.cc.d.");
DNSName parent("aaaa.bbb.cc.d.");
BOOST_CHECK(!name.isPartOf(parent));
}


DNSName left("ds9a.nl.");
left.prependRawLabel("www");
BOOST_CHECK( left == DNSName("WwW.Ds9A.Nl."));
Expand Down

0 comments on commit 02a2b54

Please sign in to comment.