From: JINMEI Tatuya Date: Wed, 15 Feb 2012 03:44:22 +0000 (-0800) Subject: [1638] an NSEC3 bug fix: reject padded base32hex string for next hash. X-Git-Tag: trac2351_base~247^2~9^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bf67156c7798685263abd1fc8c60669a78bcec2d;p=thirdparty%2Fkea.git [1638] an NSEC3 bug fix: reject padded base32hex string for next hash. also made a minor adjustment to compare() --- diff --git a/src/lib/dns/rdata/generic/nsec3_50.cc b/src/lib/dns/rdata/generic/nsec3_50.cc index 3817941b59..619f330d63 100644 --- a/src/lib/dns/rdata/generic/nsec3_50.cc +++ b/src/lib/dns/rdata/generic/nsec3_50.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -101,6 +102,11 @@ NSEC3::NSEC3(const string& nsec3_str) : << salt.size() << " bytes"); } + // Next hash must not be a padded base32hex string. + assert(!nexthash.empty()); + if (*nexthash.rbegin() == '=') { + isc_throw(InvalidRdataText, "NSEC3 hash has padding: " << nsec3_str); + } vector next; decodeBase32Hex(nexthash, next); if (next.size() > 255) { @@ -256,10 +262,10 @@ compareVectors(const vector& v1, const vector& v2, { const size_t len1 = v1.size(); const size_t len2 = v2.size(); - const size_t cmplen = min(len1, len2); if (check_length_first && len1 != len2) { return (len1 - len2); } + const size_t cmplen = min(len1, len2); const int cmp = cmplen == 0 ? 0 : memcmp(&v1.at(0), &v2.at(0), cmplen); if (cmp != 0) { return (cmp); diff --git a/src/lib/dns/tests/rdata_nsec3_unittest.cc b/src/lib/dns/tests/rdata_nsec3_unittest.cc index 4141a5a284..edd2d4b6e7 100644 --- a/src/lib/dns/tests/rdata_nsec3_unittest.cc +++ b/src/lib/dns/tests/rdata_nsec3_unittest.cc @@ -82,6 +82,10 @@ TEST_F(Rdata_NSEC3_Test, badText) { "0123456789ABCDEFGHIJKLMNOPQRSTUV A NS SOA"), InvalidRdataText); + // Next hash shouldn't be padded + EXPECT_THROW(generic::NSEC3("1 1 1 ADDAFEEE CPNMU=== A NS SOA"), + InvalidRdataText); + // Hash is too long. Max = 255 bytes, base32-hex converts each 5 bytes // of the original to 8 characters, so 260 * 8 / 5 is the smallest length // of the encoded string that exceeds the max and doesn't require padding.