From: Francis Dupont Date: Fri, 10 Jul 2026 14:46:21 +0000 (+0200) Subject: [#2260] Added iaid check X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7607525993057200ae96077f35e90ad41eac716e;p=thirdparty%2Fkea.git [#2260] Added iaid check --- diff --git a/src/hooks/dhcp/lease_cmds/lease_cmds.cc b/src/hooks/dhcp/lease_cmds/lease_cmds.cc index a2c5530a11..2f27036d78 100644 --- a/src/hooks/dhcp/lease_cmds/lease_cmds.cc +++ b/src/hooks/dhcp/lease_cmds/lease_cmds.cc @@ -766,8 +766,19 @@ LeaseCmdsImpl::getParameters(bool v6, const ConstElementPtr& params) { } x.subnet_id = static_cast(tmp128); - if (params->contains("iaid")) { - x.iaid = params->get("iaid")->intValue(); + tmp = params->get("iaid"); + if (tmp) { + if (!v6) { + isc_throw(BadValue, "'iaid' parameter is specific to DHCPv6."); + } + if (tmp->getType() != Element::integer) { + isc_throw(BadValue, "'iaid' parameter is not integer."); + } + tmp128 = tmp->intValue(); + if ((tmp128 < uint32_min) || (tmp128 > uint32_max)) { + isc_throw(BadValue, "'iaid' parameter is not a 32 bit unsigned integer."); + } + x.iaid = static_cast(tmp128); } // No address specified. Ok, so it must be identifier based query. 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 92d3cf01a6..7425bc576a 100644 --- a/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds4_unittest.cc +++ b/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds4_unittest.cc @@ -1270,6 +1270,7 @@ void Lease4CmdsTest::testLease4GetBadParam() { // Structure detailing a test scenario. struct Scenario { string name_; // name + bool add_subnet_id_; // set to true to add a subnet-id string param_; // parameter entry to test string exp_rsp_; // expected response }; @@ -1278,42 +1279,59 @@ void Lease4CmdsTest::testLease4GetBadParam() { std::vector scenarios = { { "Invalid family", + false, "\"ip-address\": \"2001:db8:1::1\"", "Invalid IPv4 address specified: 2001:db8:1::1" }, { "Bad address", + false, "\"ip-address\": \"221B Baker St.\"", "Failed to convert string to address '221B Baker St.': Invalid argument" }, { "Not numeric subnet id", + false, "\"subnet-id\": \"foo\"", "'subnet-id' parameter is not integer." }, { "Negative subnet id", + false, "\"subnet-id\": -1", "'subnet-id' parameter is not a 32 bit unsigned integer." }, { "Too large subnet id", + false, "\"subnet-id\": 4294967297", "'subnet-id' parameter is not a 32 bit unsigned integer." + }, + { + "IAID is v6 only", + true, + "\"iaid\": 0", + "'iaid' parameter is specific to DHCPv6." } }; string prefix_cmd = "{\n" " \"command\": \"lease4-get\",\n" - " \"arguments\": {" + " \"arguments\": {\n" " "; + string subnet_id = " \"subnet-id\": 1\n,"; string end_cmd = + "\n" " }\n" - "}"; + "}\n"; for (auto const& scenario : scenarios) { SCOPED_TRACE(scenario.name_); - string cmd = prefix_cmd + scenario.param_ + end_cmd; + string cmd = prefix_cmd; + if (scenario.add_subnet_id_) { + cmd += subnet_id; + } + cmd += scenario.param_ + end_cmd; testCommand(cmd, CONTROL_RESULT_ERROR, scenario.exp_rsp_); } } 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 7ea368b385..7ae572b434 100644 --- a/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc +++ b/src/hooks/dhcp/lease_cmds/libloadtests/lease_cmds6_unittest.cc @@ -1523,6 +1523,7 @@ void Lease6CmdsTest::testLease6GetBadParam() { // Structure detailing a test scenario. struct Scenario { string name_; // name + bool add_subnet_id_; // set to true to add a subnet-id string param_; // parameter entry to test string exp_rsp_; // expected response }; @@ -1531,42 +1532,71 @@ void Lease6CmdsTest::testLease6GetBadParam() { std::vector scenarios = { { "Invalid family", + false, "\"ip-address\": \"192.0.2.1\"", "Invalid IPv6 address specified: 192.0.2.1" }, { "Bad address", + false, "\"ip-address\": \"221B Baker St.\"", "Failed to convert string to address '221B Baker St.': Invalid argument" }, { "Not numeric subnet id", + false, "\"subnet-id\": \"foo\"", "'subnet-id' parameter is not integer." }, { "Negative subnet id", + false, "\"subnet-id\": -1", "'subnet-id' parameter is not a 32 bit unsigned integer." }, { "Too large subnet id", + false, "\"subnet-id\": 4294967297", "'subnet-id' parameter is not a 32 bit unsigned integer." + }, + { + "Not numeric iaid", + true, + "\"iaid\": true", + "'iaid' parameter is not integer." + }, + { + "Negative iaid", + true, + "\"iaid\": -1", + "'iaid' parameter is not a 32 bit unsigned integer." + }, + { + "Too large iaid", + true, + "\"iaid\": 4294967297", + "'iaid' parameter is not a 32 bit unsigned integer." } }; string prefix_cmd = "{\n" " \"command\": \"lease6-get\",\n" - " \"arguments\": {" + " \"arguments\": {\n" " "; + string subnet_id = " \"subnet-id\": 1\n,"; string end_cmd = + "\n" " }\n" - "}"; + "}\n"; for (auto const& scenario : scenarios) { SCOPED_TRACE(scenario.name_); - string cmd = prefix_cmd + scenario.param_ + end_cmd; + string cmd = prefix_cmd; + if (scenario.add_subnet_id_) { + cmd += subnet_id; + } + cmd += scenario.param_ + end_cmd; testCommand(cmd, CONTROL_RESULT_ERROR, scenario.exp_rsp_); } }