]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#27,!138] Fixed assertion in CQL Host Manager.
authorMarcin Siodelski <marcin@isc.org>
Mon, 26 Nov 2018 17:00:01 +0000 (18:00 +0100)
committerMarcin Siodelski <marcin@isc.org>
Wed, 28 Nov 2018 08:38:23 +0000 (03:38 -0500)
src/lib/dhcpsrv/cql_host_data_source.cc
src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc

index 48ea9b6637b1271a672be8e7b1131209a2a64da3..c70055a9dc896c887ee824acc685324454b27504 100644 (file)
@@ -2049,7 +2049,7 @@ bool
 CqlHostDataSource::del(const SubnetID& subnet_id, const asiolink::IOAddress& address) {
     HostPtr host = boost::const_pointer_cast<Host>(impl_->get4(subnet_id, address));
 
-    return (impl_->insertOrDelete(host, false));
+    return (host ? impl_->insertOrDelete(host, false) : false);
 }
 
 bool
@@ -2058,7 +2058,7 @@ CqlHostDataSource::del4(const SubnetID& subnet_id, const Host::IdentifierType& i
     HostPtr host = boost::const_pointer_cast<Host>(impl_->get4(subnet_id, identifier_type,
                                                                identifier_begin, identifier_len));
 
-    return (impl_->insertOrDelete(host, false));
+    return (host ? impl_->insertOrDelete(host, false) : false);
 }
 
 bool
@@ -2067,7 +2067,7 @@ CqlHostDataSource::del6(const SubnetID& subnet_id, const Host::IdentifierType& i
     HostPtr host = boost::const_pointer_cast<Host>(impl_->get6(subnet_id, identifier_type,
                                                                identifier_begin, identifier_len));
 
-    return (impl_->insertOrDelete(host, false));
+    return (host ? impl_->insertOrDelete(host, false) : false);
 }
 
 ConstHostCollection
index b0549451994221716e279951773ba03d65a0319f..f9f6e6a67cdba48e999cda1acfc9053361374366 100644 (file)
@@ -1364,6 +1364,12 @@ void GenericHostDataSourceTest::testDeleteByAddr4() {
 
     // ... and that it's gone after deletion.
     EXPECT_FALSE(after);
+
+    // An attempt to delete it should not cause an exception. It
+    // should return false.
+    bool result = false;
+    EXPECT_NO_THROW(result = hdsptr_->del(subnet1, IOAddress("192.0.2.1")));
+    EXPECT_FALSE(result);
 }
 
 void GenericHostDataSourceTest::testDeleteById4() {
@@ -1399,6 +1405,14 @@ void GenericHostDataSourceTest::testDeleteById4() {
 
     // ... and that it's gone after deletion.
     EXPECT_FALSE(after);
+
+    // An attempt to delete it should not cause an exception. It
+    // should return false.
+    bool result = false;
+    EXPECT_NO_THROW(result = hdsptr_->del4(subnet1, host1->getIdentifierType(),
+                                           &host1->getIdentifier()[0],
+                                           host1->getIdentifier().size()));
+    EXPECT_FALSE(result);
 }
 
 // Test checks when a IPv4 host with options is deleted that the options are
@@ -1446,6 +1460,14 @@ void GenericHostDataSourceTest::testDeleteById4Options() {
 
     // Check the options are indeed gone.
     EXPECT_EQ(0, countDBOptions4());
+
+    // An attempt to delete it should not cause an exception. It
+    // should return false.
+    bool result = false;
+    EXPECT_NO_THROW(result = hdsptr_->del4(subnet1, host1->getIdentifierType(),
+                                           &host1->getIdentifier()[0],
+                                           host1->getIdentifier().size()));
+    EXPECT_FALSE(result);
 }
 
 void GenericHostDataSourceTest::testDeleteById6() {
@@ -1482,6 +1504,14 @@ void GenericHostDataSourceTest::testDeleteById6() {
 
     // ... and that it's gone after deletion.
     EXPECT_FALSE(after);
+
+    // An attempt to delete it should not cause an exception. It
+    // should return false.
+    bool result = false;
+    EXPECT_NO_THROW(result = hdsptr_->del6(subnet1, host1->getIdentifierType(),
+                                           &host1->getIdentifier()[0],
+                                           host1->getIdentifier().size()));
+    EXPECT_FALSE(result);
 }
 
 void GenericHostDataSourceTest::testDeleteById6Options() {
@@ -1530,6 +1560,14 @@ void GenericHostDataSourceTest::testDeleteById6Options() {
 
     // Check the options are indeed gone.
     EXPECT_EQ(0, countDBReservations6());
+
+    // An attempt to delete it should not cause an exception. It
+    // should return false.
+    bool result = false;
+    EXPECT_NO_THROW(result = hdsptr_->del6(subnet1, host1->getIdentifierType(),
+                                           &host1->getIdentifier()[0],
+                                           host1->getIdentifier().size()));
+    EXPECT_FALSE(result);
 }
 
 void