]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2557] Addressed comment
authorFrancis Dupont <fdupont@isc.org>
Wed, 21 Sep 2022 13:23:24 +0000 (15:23 +0200)
committerFrancis Dupont <fdupont@isc.org>
Fri, 23 Sep 2022 12:30:08 +0000 (14:30 +0200)
ChangeLog
src/lib/dhcpsrv/host.cc
src/lib/dhcpsrv/tests/host_unittest.cc

index efa365939b085bdb4288c83e6e977e5e0ee2b28d..0325302c687ae1a878c38630d480e7ad3392d5c2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,6 @@
 2061.  [bug*]          fdupont
-       Enforce length limits on host identifier (20 for hardware
-       address, 128 for DUID and other types).
+       Enforce length limits on host identifier (20 bytes for
+       hardware address, 128 bytes for DUID and other types).
        (Gitlab #2557)
 
 2060.  [build]         andrei
index cae73590260aacbcca9399b273d3e388470d1f29..328e4ac9329acbe9548ffb33d5d557fd4b82be79 100644 (file)
@@ -361,6 +361,7 @@ Host::setIdentifier(const std::string& identifier, const std::string& name) {
     // If the identifier lacks opening and closing quote, this will return
     // an empty value, in which case we'll try to decode it as a string of
     // hexadecimal digits.
+    bool too_long = false;
     try {
         std::vector<uint8_t> binary = util::str::quotedStringToBinary(identifier);
         if (binary.empty()) {
@@ -370,7 +371,9 @@ Host::setIdentifier(const std::string& identifier, const std::string& name) {
         size_t len = binary.size();
         if (len > getIdentifierMaxLength(identifier_type_)) {
             // Message does not matter as it will be replaced below...
-            isc_throw(BadValue, "too long client identifier");
+            too_long = true;
+            isc_throw(BadValue, "too long client identifier type " << name
+                      << " length " << len);
         }
 
         // Successfully decoded the identifier, so let's use it.
@@ -379,8 +382,11 @@ Host::setIdentifier(const std::string& identifier, const std::string& name) {
     } catch (...) {
         // The string doesn't match any known pattern, so we have to
         // report an error at this point.
+        if (too_long) {
+            throw;
+        }
         isc_throw(isc::BadValue, "invalid host identifier value '"
-                      << identifier << "'");
+                  << identifier << "'");
     }
 }
 
index 478f17b32cb2ca1025f4fcb758330d1f1dee88a4..a7ee02db918402a4acaf5142b326b78cd7a377d5 100644 (file)
@@ -262,7 +262,7 @@ TEST_F(HostTest, createFromHWAddrString) {
     // Use too long HW address.
     string too_long = "00:01:02:03:04:05:06:07:08:09:0a:0b:0c:0d:0e:0f";
     too_long += ":10:11:12:13:14";
-    expected = "invalid host identifier value '" + too_long + "'";
+    expected = "too long client identifier type hw-address length 21";
     EXPECT_THROW_MSG(Host(too_long, "hw-address", SubnetID(1), SubnetID(2),
                           IOAddress("192.0.2.3"), "somehost.example.org"),
                      isc::BadValue, expected);
@@ -318,10 +318,11 @@ TEST_F(HostTest, createFromDUIDString) {
     too_long += ":60:61:62:63:64:65:66:67:68:69:6a:6b:6c:6d:6e:6f";
     too_long += ":70:71:72:73:74:75:76:77:78:79:7a:7b:7c:7d:7e:7f";
     too_long += ":ff";
-    expected = "invalid host identifier value '" + too_long + "'";
+    expected = "too long client identifier type duid length 129";
     EXPECT_THROW_MSG(Host(too_long, "duid", SubnetID(1), SubnetID(2),
                           IOAddress("192.0.2.3"), "somehost.example.org"),
                      isc::BadValue, expected);
+    expected = "too long client identifier type circuit-id length 129";
     EXPECT_THROW_MSG(Host(too_long, "circuit-id", SubnetID(1), SubnetID(2),
                           IOAddress("192.0.2.3"), "somehost.example.org"),
                      isc::BadValue, expected);