From: JINMEI Tatuya Date: Fri, 10 Feb 2012 22:03:43 +0000 (-0800) Subject: [1641] another bogus NSEC3 wire data case: RDLEN is too short to have hashlen. X-Git-Tag: trac2351_base~97^2~37^2~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b86f7c330eba5b252adbea0594c2225fbc31e2e2;p=thirdparty%2Fkea.git [1641] another bogus NSEC3 wire data case: RDLEN is too short to have hashlen. the original code would still throw an exception (bad_alloc) due to the resulting huge size of alloc request, but it should be better to catch it explicitly. --- diff --git a/src/lib/dns/rdata/generic/nsec3_50.cc b/src/lib/dns/rdata/generic/nsec3_50.cc index ab3b955519..f9c295545c 100644 --- a/src/lib/dns/rdata/generic/nsec3_50.cc +++ b/src/lib/dns/rdata/generic/nsec3_50.cc @@ -174,6 +174,10 @@ NSEC3::NSEC3(InputBuffer& buffer, size_t rdata_len) { rdata_len -= saltlen; } + if (rdata_len < 1) { + isc_throw(DNSMessageFORMERR, "NSEC3 too short to contain hash length, " + "length: " << rdata_len + saltlen + 5); + } const uint8_t nextlen = buffer.readUint8(); --rdata_len; if (nextlen == 0 || rdata_len < nextlen) { diff --git a/src/lib/dns/tests/rdata_nsec3_unittest.cc b/src/lib/dns/tests/rdata_nsec3_unittest.cc index 441c6d8f47..2f85920187 100644 --- a/src/lib/dns/tests/rdata_nsec3_unittest.cc +++ b/src/lib/dns/tests/rdata_nsec3_unittest.cc @@ -165,7 +165,11 @@ TEST_F(Rdata_NSEC3_Test, createFromWire) { "rdata_nsec3_fromWire14.wire"), DNSMessageFORMERR); - // + // RDLEN is too short to hold the hash length field + EXPECT_THROW(rdataFactoryFromFile(RRType::NSEC3(), RRClass::IN(), + "rdata_nsec3_fromWire17.wire"), + DNSMessageFORMERR); + // Short buffer cases. The data is valid NSEC3 RDATA, but the buffer // is trimmed at the end. All cases should result in an exception from // the buffer class. diff --git a/src/lib/dns/tests/testdata/Makefile.am b/src/lib/dns/tests/testdata/Makefile.am index c459977673..dbff12e0ec 100644 --- a/src/lib/dns/tests/testdata/Makefile.am +++ b/src/lib/dns/tests/testdata/Makefile.am @@ -29,7 +29,7 @@ BUILT_SOURCES += rdata_nsec3_fromWire8.wire rdata_nsec3_fromWire9.wire BUILT_SOURCES += rdata_nsec3_fromWire10.wire rdata_nsec3_fromWire11.wire BUILT_SOURCES += rdata_nsec3_fromWire12.wire rdata_nsec3_fromWire13.wire BUILT_SOURCES += rdata_nsec3_fromWire14.wire rdata_nsec3_fromWire15.wire -BUILT_SOURCES += rdata_nsec3_fromWire16.wire +BUILT_SOURCES += rdata_nsec3_fromWire16.wire rdata_nsec3_fromWire17.wire BUILT_SOURCES += rdata_rrsig_fromWire2.wire BUILT_SOURCES += rdata_minfo_fromWire1.wire rdata_minfo_fromWire2.wire BUILT_SOURCES += rdata_minfo_fromWire3.wire rdata_minfo_fromWire4.wire @@ -102,7 +102,7 @@ EXTRA_DIST += rdata_nsec_fromWire4.spec rdata_nsec_fromWire5.spec EXTRA_DIST += rdata_nsec_fromWire6.spec rdata_nsec_fromWire7.spec EXTRA_DIST += rdata_nsec_fromWire8.spec rdata_nsec_fromWire9.spec EXTRA_DIST += rdata_nsec_fromWire10.spec -EXTRA_DIST += rdata_nsec_fromWire16.spec +EXTRA_DIST += rdata_nsec_fromWire16.spec rdata_nsec_fromWire17.spec EXTRA_DIST += rdata_nsec3param_fromWire1 EXTRA_DIST += rdata_nsec3_fromWire1 EXTRA_DIST += rdata_nsec3_fromWire2.spec rdata_nsec3_fromWire3 diff --git a/src/lib/dns/tests/testdata/rdata_nsec3_fromWire17.spec b/src/lib/dns/tests/testdata/rdata_nsec3_fromWire17.spec new file mode 100644 index 0000000000..42533491bf --- /dev/null +++ b/src/lib/dns/tests/testdata/rdata_nsec3_fromWire17.spec @@ -0,0 +1,8 @@ +# +# An invalid NSEC3 RDATA: RDLEN is too short to include the hash len field. +# + +[custom] +sections: nsec3 +[nsec3] +rdlen: 10