]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2873] null check to prevent crash in GenericLeaseMgrTest
authorAndrei Pavel <andrei@isc.org>
Tue, 23 May 2023 09:21:49 +0000 (12:21 +0300)
committerAndrei Pavel <andrei@isc.org>
Tue, 23 May 2023 09:21:49 +0000 (12:21 +0300)
src/lib/dhcpsrv/cfg_subnets4.cc
src/lib/dhcpsrv/cfg_subnets4.h
src/lib/dhcpsrv/cfg_subnets6.cc
src/lib/dhcpsrv/cfg_subnets6.h
src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc

index aaebbd693a7a682650c82f741f566994cc420c2a..a621c4d4a6e97b1b9581dd710576b6e13cfc49d0 100644 (file)
@@ -584,6 +584,11 @@ CfgSubnets4::initAllocatorsAfterConfigure() {
     }
 }
 
+void
+CfgSubnets4::clear() {
+    subnets_.clear();
+}
+
 ElementPtr
 CfgSubnets4::toElement() const {
     ElementPtr result = Element::createList();
index d2e50e0d5a33831dfe1289c1448009879af01675..84367bb273ecc2908371f1f6ab5a019d864a92f6 100644 (file)
@@ -330,6 +330,9 @@ public:
     /// @brief Calls @c initAllocatorsAfterConfigure for each subnet.
     void initAllocatorsAfterConfigure();
 
+    /// @brief Clears all subnets from the configuration.
+    void clear();
+
     /// @brief Unparse a configuration object
     ///
     /// @return a pointer to unparsed configuration
index 819d77adedc1615a8fdc64132f6870d73461849f..ef22436626eff1d700f08aa5278c2e53661982db 100644 (file)
@@ -494,6 +494,11 @@ CfgSubnets6::initAllocatorsAfterConfigure() {
     }
 }
 
+void
+CfgSubnets6::clear() {
+    subnets_.clear();
+}
+
 ElementPtr
 CfgSubnets6::toElement() const {
     ElementPtr result = Element::createList();
index 089e3a7c0345585196f723a30eb2d3dc5ae7db8d..b21c808193c38ce5c153a1151326e9622153b748 100644 (file)
@@ -280,6 +280,9 @@ public:
     /// @brief Calls @c initAllocatorsAfterConfigure for each subnet.
     void initAllocatorsAfterConfigure();
 
+    /// @brief Clears all subnets from the configuration.
+    void clear();
+
     /// @brief Unparse a configuration object
     ///
     /// @return a pointer to unparsed configuration
index 93e132dbe5568460b9fa6945c1d08885e4c7b90a..c42ab8092b3df4539c7cd37afcae6f5e606ceff0 100644 (file)
@@ -84,12 +84,8 @@ GenericLeaseMgrTest::GenericLeaseMgrTest()
     }
 
     // Clear all subnets defined in previous tests.
-    for (Subnet4Ptr const& subnet : *CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->getAll()) {
-        CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->del(subnet);
-    }
-    for (Subnet6Ptr const& subnet : *CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->getAll()) {
-        CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->del(subnet);
-    }
+    CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->clear();
+    CfgMgr::instance().getStagingCfg()->getCfgSubnets6()->clear();
 
     // Clear all stats.
     StatsMgr::instance().removeAll();