diff --git a/src/lib/dns/cpp/name.cc b/src/lib/dns/cpp/name.cc index ebb81eaacf..5139409309 100644 --- a/src/lib/dns/cpp/name.cc +++ b/src/lib/dns/cpp/name.cc @@ -241,7 +241,7 @@ Name::Name(InputBuffer& buffer, bool downcase) { unsigned int new_current; std::vector offsets; - offsets.reserve(Name::MAX_WIRE / 2); + offsets.reserve(Name::MAX_LABELS); /* * Initialize things to make the compiler happy; they're not required. @@ -562,7 +562,6 @@ Name::concatenate(const Name& suffix) const transform(suffix.offsets_.begin(), suffix.offsets_.end(), back_inserter(retname.offsets_), bind2nd(OffsetAdjuster(), this->length_ - 1)); - assert(retname.offsets_.back() == retname.length_ - 1); assert(retname.offsets_.size() == labels); retname.labels_ = labels; diff --git a/src/lib/dns/cpp/name_unittest.cc b/src/lib/dns/cpp/name_unittest.cc index 9af636a3d3..7c844b55e8 100644 --- a/src/lib/dns/cpp/name_unittest.cc +++ b/src/lib/dns/cpp/name_unittest.cc @@ -38,6 +38,7 @@ protected: NameTest() : example_name("www.example.com") {} Name example_name; + static const size_t MAX_WIRE = Name::MAX_WIRE; static const size_t MAX_LABELS = Name::MAX_LABELS; // // helper methods @@ -176,6 +177,24 @@ TEST_F(NameTest, fromWire) EXPECT_EQ(true, nameFactoryFromWire("testdata/name_fromWire8", 383) == Name("vix.com")); + // + // Additional test cases + // + + // large names, a long but valid one, and invalid (too long) one. + EXPECT_EQ(MAX_WIRE, + nameFactoryFromWire("testdata/name_fromWire9", 0).getLength()); + EXPECT_THROW(nameFactoryFromWire("testdata/name_fromWire10", 0).getLength(), + isc::dns::TooLongName); + + // A name with possible maximum number of labels; awkward but valid + EXPECT_EQ(nameFactoryFromWire("testdata/name_fromWire11", 0).getLabels(), + MAX_LABELS); + + // Wire format including an invalid label length + EXPECT_THROW(nameFactoryFromWire("testdata/name_fromWire12", 0), + isc::dns::BadLabelType); + // converting upper-case letters to down-case EXPECT_EQ("vix.com.", nameFactoryFromWire("testdata/name_fromWire1", 25, true).toText()); diff --git a/src/lib/dns/cpp/testdata/name_fromWire10 b/src/lib/dns/cpp/testdata/name_fromWire10 new file mode 100644 index 0000000000..65be775e2f --- /dev/null +++ b/src/lib/dns/cpp/testdata/name_fromWire10 @@ -0,0 +1,12 @@ +# +# Too large name; should trigger an exception. +# +09010203040506070809 09010203040506070809 09010203040506070809 +09010203040506070809 09010203040506070809 09010203040506070809 +09010203040506070809 09010203040506070809 09010203040506070809 +09010203040506070809 09010203040506070809 09010203040506070809 +09010203040506070809 09010203040506070809 09010203040506070809 +09010203040506070809 09010203040506070809 09010203040506070809 +09010203040506070809 09010203040506070809 09010203040506070809 +09010203040506070809 09010203040506070809 09010203040506070809 +09010203040506070809 040102030400 diff --git a/src/lib/dns/cpp/testdata/name_fromWire11 b/src/lib/dns/cpp/testdata/name_fromWire11 new file mode 100644 index 0000000000..32184f6758 --- /dev/null +++ b/src/lib/dns/cpp/testdata/name_fromWire11 @@ -0,0 +1,12 @@ +# +# A name with possible maximum number of labels; should be accepted safely. +# +01000100010001000100 01000100010001000100 01000100010001000100 +01000100010001000100 01000100010001000100 01000100010001000100 +01000100010001000100 01000100010001000100 01000100010001000100 +01000100010001000100 01000100010001000100 01000100010001000100 +01000100010001000100 01000100010001000100 01000100010001000100 +01000100010001000100 01000100010001000100 01000100010001000100 +01000100010001000100 01000100010001000100 01000100010001000100 +01000100010001000100 01000100010001000100 01000100010001000100 +01000100010001000100 0100010000 diff --git a/src/lib/dns/cpp/testdata/name_fromWire12 b/src/lib/dns/cpp/testdata/name_fromWire12 new file mode 100644 index 0000000000..073adda486 --- /dev/null +++ b/src/lib/dns/cpp/testdata/name_fromWire12 @@ -0,0 +1,13 @@ +# +# Wire format including an invalid label length +# +#(1) a (7) e x a m p l e + 01 61 07 65 78 61 6d 70 6c 65 +# invalid label length: 64 +40 +# a "label" of 64 characters: shouldn't be parsed +00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f +10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f +20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f +30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f +00 diff --git a/src/lib/dns/cpp/testdata/name_fromWire9 b/src/lib/dns/cpp/testdata/name_fromWire9 new file mode 100644 index 0000000000..79b2978e8c --- /dev/null +++ b/src/lib/dns/cpp/testdata/name_fromWire9 @@ -0,0 +1,12 @@ +# +# A possible longest name; should be accepted safely. +# +09010203040506070809 09010203040506070809 09010203040506070809 +09010203040506070809 09010203040506070809 09010203040506070809 +09010203040506070809 09010203040506070809 09010203040506070809 +09010203040506070809 09010203040506070809 09010203040506070809 +09010203040506070809 09010203040506070809 09010203040506070809 +09010203040506070809 09010203040506070809 09010203040506070809 +09010203040506070809 09010203040506070809 09010203040506070809 +09010203040506070809 09010203040506070809 09010203040506070809 +09010203040506070809 0301020300