]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2260] More fixes including for #4395
authorFrancis Dupont <fdupont@isc.org>
Sat, 11 Jul 2026 09:09:53 +0000 (11:09 +0200)
committerFrancis Dupont <fdupont@isc.org>
Sat, 11 Jul 2026 09:09:53 +0000 (11:09 +0200)
src/hooks/dhcp/lease_cmds/lease_cmds.cc
src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds4_unittest.cc
src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc

index 2f27036d78dc3bb46a4542088015621b0d5e8007..150edd12c90795e2567787d7358b7456d39d37e6 100644 (file)
@@ -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);
index 7425bc576a5fe558f981124530c8b6b2a1693060..14573233e171595a4dccd0625af11b63a7d9e4db 100644 (file)
@@ -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.
index 7ae572b4345e7f6a3cdc8e99210cb4f0fd224c11..f7f57c6f182a75bc62d60f3ce4a95ddf05e4bea2 100644 (file)
@@ -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.