]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4692] Added UTs
authorFrancis Dupont <fdupont@isc.org>
Sun, 2 Aug 2026 13:13:50 +0000 (15:13 +0200)
committerFrancis Dupont <fdupont@isc.org>
Mon, 10 Aug 2026 21:07:07 +0000 (23:07 +0200)
changelog_unreleased/4692-limit-v6-vendor-options-recursion [new file with mode: 0644]
src/lib/dhcp/libdhcp++.cc
src/lib/dhcp/tests/libdhcp++_unittest.cc

diff --git a/changelog_unreleased/4692-limit-v6-vendor-options-recursion b/changelog_unreleased/4692-limit-v6-vendor-options-recursion
new file mode 100644 (file)
index 0000000..c93e5d2
--- /dev/null
@@ -0,0 +1,3 @@
+[bug]          fdupont
+       Limited recursive unpacking of DHCPv6 vendor options.
+       (Gitlab #4692)
index dc53730762599a0b0b82ad5e15e40d2b263f6251..7e6e427115422fdf8700666f24af5e5acca732db 100644 (file)
@@ -861,7 +861,8 @@ LibDHCP::unpackVendorOptions6(const uint32_t vendor_id, const OptionBuffer& buf,
                               size_t rec_level /* = 0 */) {
     ++rec_level;
     if (rec_level >= MAX_RECURSION_LEVEL) {
-        isc_throw(isc::Unexpected, "Too deep recursion in unpacking options");
+        isc_throw(isc::Unexpected,
+                  "Too deep recursion in unpacking vendor options");
     }
     size_t offset = 0;
     size_t length = buf.size();
index c719cd6a2ede27dda36ee68507ee14ddcfb867f8..845b483f5c7a4c16dbea7276d6244546c2e798c9 100644 (file)
@@ -3979,6 +3979,16 @@ TEST_F(LibDhcpTest, tooDeepRecursionUnpackOptions6) {
         Unexpected, "Too deep recursion in unpacking options");
 }
 
+// Check that too deep recursion throws in unpackVendorOptions6.
+TEST_F(LibDhcpTest, tooDeepRecursionUnpackVendorOptions6) {
+    OptionBuffer buf;
+    OptionCollection options;
+    ASSERT_THROW_MSG(
+        LibDHCP::unpackVendorOptions6(1234, buf, options,
+                                      LibDHCP::MAX_RECURSION_LEVEL - 1),
+        Unexpected, "Too deep recursion in unpacking vendor options");
+}
+
 // Check that too deep recursion throws with client-data custom option.
 TEST_F(LibDhcpTest, tooDeepRecursionClientData) {
     OptionDefContainerPtr options = LibDHCP::getOptionDefs(DHCP6_OPTION_SPACE);
@@ -4137,6 +4147,24 @@ TEST_F(LibDhcpTest, tooDeepRecursionSequence) {
     EXPECT_NO_THROW(LibDHCP::unpackOptions6(buf, space, options));
 }
 
+// Check that too deep recursion throws with vendor-opts special option.
+TEST_F(LibDhcpTest, tooDeepRecursionVendorOps) {
+    OptionBuffer buf = {
+        0, D6O_VENDOR_OPTS,     // type vendor-opts
+        0, 10,                  // length
+        12, 23, 45, 67,         // vendor id
+        0, 10,                  // sub-option type
+        0, 2,                   // sub-option length
+        1, 2                    // sub-option content
+    };
+    string space = DHCP6_OPTION_SPACE;
+    OptionCollection options;
+    ASSERT_THROW_MSG(
+        LibDHCP::unpackOptions6(buf, space, options, 0, 0,
+                                LibDHCP::MAX_RECURSION_LEVEL - 2),
+        Unexpected, "Too deep recursion in unpacking vendor options");
+}
+
 // This test verifies that unpackOptions4() throws on a scalar
 // option if it's stated length does not match the defined type
 // length and lenient parsing is disabled..