From: Marcin Siodelski Date: Mon, 26 Nov 2018 17:00:01 +0000 (+0100) Subject: [#27,!138] Fixed assertion in CQL Host Manager. X-Git-Tag: 284-need-dhcp6-example-for-netconf_base~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca15b7607d3564b061717526e86562cb0abce343;p=thirdparty%2Fkea.git [#27,!138] Fixed assertion in CQL Host Manager. --- diff --git a/src/lib/dhcpsrv/cql_host_data_source.cc b/src/lib/dhcpsrv/cql_host_data_source.cc index 48ea9b6637..c70055a9dc 100644 --- a/src/lib/dhcpsrv/cql_host_data_source.cc +++ b/src/lib/dhcpsrv/cql_host_data_source.cc @@ -2049,7 +2049,7 @@ bool CqlHostDataSource::del(const SubnetID& subnet_id, const asiolink::IOAddress& address) { HostPtr host = boost::const_pointer_cast(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(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(impl_->get6(subnet_id, identifier_type, identifier_begin, identifier_len)); - return (impl_->insertOrDelete(host, false)); + return (host ? impl_->insertOrDelete(host, false) : false); } ConstHostCollection diff --git a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc index b054945199..f9f6e6a67c 100644 --- a/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_host_data_source_unittest.cc @@ -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