From: Francis Dupont Date: Sat, 11 Jul 2026 09:09:53 +0000 (+0200) Subject: [#2260] More fixes including for #4395 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=049d0ad5d1e0d67687cbfc65e7532a4b0758e079;p=thirdparty%2Fkea.git [#2260] More fixes including for #4395 --- diff --git a/src/hooks/dhcp/lease_cmds/lease_cmds.cc b/src/hooks/dhcp/lease_cmds/lease_cmds.cc index 2f27036d78..150edd12c9 100644 --- a/src/hooks/dhcp/lease_cmds/lease_cmds.cc +++ b/src/hooks/dhcp/lease_cmds/lease_cmds.cc @@ -100,9 +100,7 @@ public: /// /// @throw BadValue if unsupported type is specified static Type txtToType(const std::string& txt) { - if (txt == "address") { - return (Parameters::TYPE_ADDR); - } else if (txt == "hw-address") { + if (txt == "hw-address") { return (Parameters::TYPE_HWADDR); } else if (txt == "duid") { return (Parameters::TYPE_DUID); @@ -111,7 +109,7 @@ public: } else { isc_throw(BadValue, "Incorrect identifier type: " << txt << ", the only supported values are: " - "address, hw-address, duid, client-id"); + "hw-address, duid, client-id"); } } @@ -801,30 +799,33 @@ LeaseCmdsImpl::getParameters(bool v6, const ConstElementPtr& params) { x.query_type = Parameters::txtToType(type->stringValue()); switch (x.query_type) { - case Parameters::TYPE_HWADDR: { - HWAddr hw = HWAddr::fromText(ident->stringValue()); - x.hwaddr = HWAddrPtr(new HWAddr(hw)); + case Parameters::TYPE_HWADDR: + try { + HWAddr hw = HWAddr::fromText(ident->stringValue()); + x.hwaddr = HWAddrPtr(new HWAddr(hw)); + } catch (const std::exception& ex) { + isc_throw(BadValue, "Bad 'hw-address' identifier: " << ex.what()); + } break; - } - case Parameters::TYPE_CLIENT_ID: { - x.client_id = ClientId::fromText(ident->stringValue()); + case Parameters::TYPE_CLIENT_ID: + try { + x.client_id = ClientId::fromText(ident->stringValue()); + } catch (const std::exception& ex) { + isc_throw(BadValue, "Bad 'client-id' identifier: " << ex.what()); + } break; - } - case Parameters::TYPE_DUID: { - DUID duid = DUID::fromText(ident->stringValue()); - x.duid = DuidPtr(new DUID(duid)); + case Parameters::TYPE_DUID: + try { + DUID duid = DUID::fromText(ident->stringValue()); + x.duid = DuidPtr(new DUID(duid)); + } catch (const std::exception& ex) { + isc_throw(BadValue, "Bad 'duid' identifier: " << ex.what()); + } break; - } - case Parameters::TYPE_ADDR: { - // We should never get here. The address clause should have been caught - // earlier. - return (x); - } - default: { + default: isc_throw(BadValue, "Identifier type " << type->stringValue() << " is not supported."); } - } return (x); } @@ -1153,10 +1154,14 @@ LeaseCmdsImpl::leaseGetByHwAddressHandler(CalloutHandle& handle) { isc_throw(BadValue, "'hw-address' parameter must not be empty"); } - HWAddr hwaddr = HWAddr::fromText(hw_address->stringValue()); + HWAddr hwaddr; + try { + hwaddr = HWAddr::fromText(hw_address->stringValue()); + } catch (const std::exception& ex) { + isc_throw(BadValue, "bad 'hw-address' parameter: " << ex.what()); + } ElementPtr leases_json = Element::createList(); - if (v4) { Lease4Collection leases = LeaseMgrFactory::instance().getLease4(hwaddr); diff --git a/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds4_unittest.cc b/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds4_unittest.cc index 7425bc576a..14573233e1 100644 --- a/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds4_unittest.cc +++ b/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds4_unittest.cc @@ -1225,7 +1225,7 @@ void Lease4CmdsTest::testLease4GetMissingParams() { " }\n" "}"; exp_rsp = "Incorrect identifier type: color, the only supported values are: " - "address, hw-address, duid, client-id"; + "hw-address, duid, client-id"; testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp); // Query by DUID is not supported in v4. Sorry. @@ -1312,6 +1312,41 @@ void Lease4CmdsTest::testLease4GetBadParam() { true, "\"iaid\": 0", "'iaid' parameter is specific to DHCPv6." + }, + { + "Unknown identifier type", + true, + "\"identifier-type\": \"color\", \"identifier\": \"blue\"", + "Incorrect identifier type: color, the only supported values are: " + "hw-address, duid, client-id" + }, + { + "Bad address identifier type", + true, + "\"identifier-type\": \"address\", \"identifier\": \"blue\"", + "Incorrect identifier type: address, the only supported values " + "are: hw-address, duid, client-id" + }, + { + "Bad hw-address identifier", + true, + "\"identifier-type\": \"hw-address\", \"identifier\": \"01::\"", + "Bad 'hw-address' identifier: " + "two consecutive separators (':') specified in a decoded string '01::'" + }, + { + "Bad client-id identifier", + true, + "\"identifier-type\": \"client-id\", \"identifier\": \"01\"", + "Bad 'client-id' identifier: " + "identifier is too short (1), at least 2 is required" + }, + { + "Bad duid identifier", + true, + "\"identifier-type\": \"duid\", \"identifier\": \"01\"", + "Bad 'duid' identifier: " + "identifier is too short (1), at least 3 is required" } }; @@ -1930,7 +1965,8 @@ void Lease4CmdsTest::testLease4GetByHwAddressParams() { " \"hw-address\": \"00::01:00:bc:0d:67\"\n" " }\n" "}"; - exp_rsp = "two consecutive separators (':') specified in a decoded string"; + exp_rsp = "bad 'hw-address' parameter: "; + exp_rsp += "two consecutive separators (':') specified in a decoded string"; exp_rsp += " '00::01:00:bc:0d:67'"; testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp); } @@ -3013,7 +3049,7 @@ void Lease4CmdsTest::testLease4DelMissingParams() { " }\n" "}"; exp_rsp = "Incorrect identifier type: color, the only supported values are: " - "address, hw-address, duid, client-id"; + "hw-address, duid, client-id"; testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp); // Query by DUID is not supported in v4. Sorry. diff --git a/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc b/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc index 7ae572b434..f7f57c6f18 100644 --- a/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc +++ b/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc @@ -1478,7 +1478,7 @@ void Lease6CmdsTest::testLease6GetMissingParams() { " }\n" "}"; exp_rsp = "Incorrect identifier type: color, the only supported values are: " - "address, hw-address, duid, client-id"; + "hw-address, duid, client-id"; testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp); // Query by hw-address is not supported in v6. Sorry. @@ -1577,6 +1577,41 @@ void Lease6CmdsTest::testLease6GetBadParam() { true, "\"iaid\": 4294967297", "'iaid' parameter is not a 32 bit unsigned integer." + }, + { + "Unknown identifier type", + true, + "\"identifier-type\": \"color\", \"identifier\": \"blue\"", + "Incorrect identifier type: color, the only supported values are: " + "hw-address, duid, client-id" + }, + { + "Bad address identifier type", + true, + "\"identifier-type\": \"address\", \"identifier\": \"blue\"", + "Incorrect identifier type: address, the only supported values " + "are: hw-address, duid, client-id" + }, + { + "Bad hw-address identifier", + true, + "\"identifier-type\": \"hw-address\", \"identifier\": \"01::\"", + "Bad 'hw-address' identifier: " + "two consecutive separators (':') specified in a decoded string '01::'" + }, + { + "Bad client-id identifier", + true, + "\"identifier-type\": \"client-id\", \"identifier\": \"01\"", + "Bad 'client-id' identifier: " + "identifier is too short (1), at least 2 is required" + }, + { + "Bad duid identifier", + true, + "\"identifier-type\": \"duid\", \"identifier\": \"01\"", + "Bad 'duid' identifier: " + "identifier is too short (1), at least 3 is required" } }; @@ -2207,7 +2242,8 @@ void Lease6CmdsTest::testLease6GetByHwAddressParams() { " \"hw-address\": \"00::01:00:bc:0d:67\"\n" " }\n" "}"; - exp_rsp = "two consecutive separators (':') specified in a decoded string"; + exp_rsp = "bad 'hw-address' parameter: "; + exp_rsp += "two consecutive separators (':') specified in a decoded string"; exp_rsp += " '00::01:00:bc:0d:67'"; testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp); } @@ -3464,7 +3500,7 @@ void Lease6CmdsTest::testLease6DelMissingParams() { " }\n" "}"; exp_rsp = "Incorrect identifier type: color, the only supported values are: " - "address, hw-address, duid, client-id"; + "hw-address, duid, client-id"; testCommand(cmd, CONTROL_RESULT_ERROR, exp_rsp); // Query by hw-address is not supported in v6. Sorry.