]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
minor changes 93/head
authormayya <mayya@itwm.fraunhofer.de>
Mon, 18 Jun 2018 13:51:16 +0000 (15:51 +0200)
committermayya <mayya@itwm.fraunhofer.de>
Mon, 18 Jun 2018 13:51:16 +0000 (15:51 +0200)
src/lib/dhcp/option6_auth.cc
src/lib/dhcp/option6_auth.h
src/lib/dhcp/tests/option6_auth_unittest.cc

index 4f9b364cf91c5ae97c4de5a67f22d046b8a37b2f..bf68d5616455518cad6c04a28bb39944527d32a4 100644 (file)
@@ -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
index dfaa6004524243dce906c3bd25b85615a3fd736d..7ebfe393f4a04d06a574c01b008f0b66a3697e22 100644 (file)
@@ -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
index 7891af141d94daf4d64ba1b864b386206521daac..6c9cd898b17ff679f13ece0b9f9335be27a62b12 100644 (file)
@@ -95,7 +95,7 @@ TEST_F(Option6AuthTest, setFields) {
     std::vector<uint8_t> 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<uint8_t> test_buf(16,0xa8);
     std::vector<uint8_t> 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<Option6Auth> auth;
+
+     std::vector<uint8_t> 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