From: Francis Dupont Date: Wed, 21 Sep 2022 13:23:24 +0000 (+0200) Subject: [#2557] Addressed comment X-Git-Tag: Kea-2.3.1~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a6f663eb72db37ba1edba8563dbcb9057a3e6bae;p=thirdparty%2Fkea.git [#2557] Addressed comment --- diff --git a/ChangeLog b/ChangeLog index efa365939b..0325302c68 100644 --- 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 diff --git a/src/lib/dhcpsrv/host.cc b/src/lib/dhcpsrv/host.cc index cae7359026..328e4ac932 100644 --- a/src/lib/dhcpsrv/host.cc +++ b/src/lib/dhcpsrv/host.cc @@ -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 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 << "'"); } } diff --git a/src/lib/dhcpsrv/tests/host_unittest.cc b/src/lib/dhcpsrv/tests/host_unittest.cc index 478f17b32c..a7ee02db91 100644 --- a/src/lib/dhcpsrv/tests/host_unittest.cc +++ b/src/lib/dhcpsrv/tests/host_unittest.cc @@ -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);