From: mayya Date: Mon, 18 Jun 2018 13:51:16 +0000 (+0200) Subject: minor changes X-Git-Tag: trac5694_base~2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=085400eef1df3062e7a1f6b018d5dcddf7166155;p=thirdparty%2Fkea.git minor changes --- diff --git a/src/lib/dhcp/option6_auth.cc b/src/lib/dhcp/option6_auth.cc index 4f9b364cf9..bf68d56164 100644 --- a/src/lib/dhcp/option6_auth.cc +++ b/src/lib/dhcp/option6_auth.cc @@ -37,9 +37,9 @@ Option6Auth::clone() const { void Option6Auth::pack(isc::util::OutputBuffer& buf) const { - if (buf.getCapacity() < (OPTION6_AUTH_MIN_LEN + OPTION6_HASH_MSG_LEN)) { - isc_throw(OutOfRange, "Option " << type_ << "No space for" - "computing packing data"); + if (buf.getCapacity() < (OPTION6_AUTH_MIN_LEN + OPTION6_HASH_MSG_LEN + OPTION6_HDR)) { + isc_throw(OutOfRange, "Option " << type_ << "Buffer too small for" + "packing data"); } //header = option code + length @@ -64,8 +64,8 @@ Option6Auth::pack(isc::util::OutputBuffer& buf) const { void Option6Auth::packHashInput(isc::util::OutputBuffer& buf) const { - if (buf.getCapacity() < (OPTION6_AUTH_MIN_LEN + OPTION6_HASH_MSG_LEN)) { - isc_throw(OutOfRange, "Option " << type_ << "No space for" + if (buf.getCapacity() < (OPTION6_AUTH_MIN_LEN + OPTION6_HASH_MSG_LEN + OPTION6_HDR)) { + isc_throw(OutOfRange, "Option " << type_ << "Buffer too small for" "computing hash input"); } @@ -120,7 +120,7 @@ Option6Auth::toText(int indent) const { output << in << "protocol= " << protocol_ << "algorithm= " << algorithm_ << "rdm method= " << rdm_method_ << "rdm value= " << rdm_value_ ; - return std::string(output); + return output.str(); } } // end namespace dhcp diff --git a/src/lib/dhcp/option6_auth.h b/src/lib/dhcp/option6_auth.h index dfaa600452..7ebfe393f4 100644 --- a/src/lib/dhcp/option6_auth.h +++ b/src/lib/dhcp/option6_auth.h @@ -25,8 +25,9 @@ class Option6Auth: public Option { public: - static const uint8_t OPTION6_AUTH_MIN_LEN = 11; - static const uint8_t OPTION6_HASH_MSG_LEN = 16; + static const uint8_t OPTION6_AUTH_MIN_LEN = 11; + static const uint8_t OPTION6_HASH_MSG_LEN = 16; + static const uint8_t OPTION6_HDR = 4; /// @brief Constructor, used for auth options while transmitting /// /// @param proto protocol type diff --git a/src/lib/dhcp/tests/option6_auth_unittest.cc b/src/lib/dhcp/tests/option6_auth_unittest.cc index 7891af141d..6c9cd898b1 100644 --- a/src/lib/dhcp/tests/option6_auth_unittest.cc +++ b/src/lib/dhcp/tests/option6_auth_unittest.cc @@ -95,7 +95,7 @@ TEST_F(Option6AuthTest, setFields) { std::vector test_buf(16,0xa8); auth.reset(new Option6Auth(1,2,0,0x0090000000000000,test_buf)); - isc::util::OutputBuffer buf(29);//2 header + fixed 11 and key 16 + isc::util::OutputBuffer buf(31);//4 header + fixed 11 and key 16 ASSERT_NO_THROW(auth->pack(buf)); const uint8_t ref_data[] = { @@ -118,14 +118,14 @@ TEST_F(Option6AuthTest, checkHashInput) { std::vector test_buf(16,0xa8); std::vector hash_op(16,0x00); - auth.reset(new Option6Auth(1,2,0,0x0090000000000000,test_buf)); + auth.reset(new Option6Auth(1,2,0,0x0102030405060708,test_buf)); - isc::util::OutputBuffer buf(29); - auth->packHashInput(buf); - //auth info must be 0 for calculating the checksum + isc::util::OutputBuffer buf(31); + ASSERT_NO_THROW(auth->packHashInput(buf)); + //auth info must be 0 for calculating the checksum const uint8_t ref_data[] = { 0, 11, 0, 27, 1, 2, 0, //header , proto algo method - 0, 0x90, 0, 0, 0, 0, 0, 0, //64 bit rdm field + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, //64 bit rdm field 0x00, 0x00, 0x00, 0x00, //128 bits/16 byte key 0x00, 0x00, 0x00, 0x00, //128 bits/16 byte key 0x00, 0x00, 0x00, 0x00, //128 bits/16 byte key @@ -138,4 +138,17 @@ TEST_F(Option6AuthTest, checkHashInput) { ASSERT_EQ(0, memcmp(ref_data, buf.getData(), buf.getLength())); } +TEST_F(Option6AuthTest, negativeCase) { + scoped_ptr auth; + + std::vector test_buf(16,0xa8); + auth.reset(new Option6Auth(1,2,0,0x0102030405060708,test_buf)); + //allocate less space to force an exception to be thrown + isc::util::OutputBuffer buf(20); + + ASSERT_THROW(auth->pack(buf), isc::OutOfRange); + ASSERT_THROW(auth->packHashInput(buf), isc::OutOfRange); + +} + } //end namespace