diff --git a/src/hooks/dhcp/lease_cmds/lease_cmds.cc b/src/hooks/dhcp/lease_cmds/lease_cmds.cc index 0a19bea1b6..72f93761a8 100644 --- a/src/hooks/dhcp/lease_cmds/lease_cmds.cc +++ b/src/hooks/dhcp/lease_cmds/lease_cmds.cc @@ -2794,6 +2794,10 @@ LeaseCmdsImpl::leases4Committed(CalloutHandle& callout_handle, callout_handle.getArgument("response4", response); callout_handle.getArgument("leases4", leases); + if (!leases) { + isc_throw(Unexpected, "leases4Committed - leases is null"); + } + // In some cases we may have no lease, e.g. DHCPNAK, // or no response e.g. DHCPRELEASE. if (leases->empty() || !response || (response->getType() != DHCPACK)) { @@ -2802,7 +2806,7 @@ LeaseCmdsImpl::leases4Committed(CalloutHandle& callout_handle, Lease4Ptr lease = (*leases)[0]; if (!lease) { - isc_throw(Unexpected, "leases4Committed - no lease!"); + isc_throw(Unexpected, "leases4Committed - lease is null"); } try { @@ -2832,6 +2836,10 @@ LeaseCmdsImpl::leases6Committed(CalloutHandle& callout_handle, callout_handle.getArgument("response6", response); callout_handle.getArgument("leases6", leases); + if (!leases) { + isc_throw(Unexpected, "leases6Committed - leases is null"); + } + // In some cases we may have no active leases or no response. if (leases->empty() || !response) { return; @@ -2841,6 +2849,10 @@ LeaseCmdsImpl::leases6Committed(CalloutHandle& callout_handle, int failed = 0; for (auto lease : *leases) { try { + if (!lease) { + isc_throw(Unexpected, "leases6Committed - lease is null"); + } + /// @todo - Users might want to only update NA or PD leases. /// This could be done via adding a lease type to the variable. /// V4 would not use it, for V6 it would restrict a variable diff --git a/src/lib/dhcpsrv/lease.cc b/src/lib/dhcpsrv/lease.cc index a3a7568dff..d28580c3de 100644 --- a/src/lib/dhcpsrv/lease.cc +++ b/src/lib/dhcpsrv/lease.cc @@ -383,6 +383,7 @@ Lease4::decline(uint32_t probation_period) { fqdn_rev_ = false; state_ = STATE_DECLINED; valid_lft_ = probation_period; + setContext(ElementPtr()); } isc::data::ElementPtr diff --git a/src/lib/dhcpsrv/tests/lease_unittest.cc b/src/lib/dhcpsrv/tests/lease_unittest.cc index 024af51857..98222e760c 100644 --- a/src/lib/dhcpsrv/tests/lease_unittest.cc +++ b/src/lib/dhcpsrv/tests/lease_unittest.cc @@ -593,6 +593,9 @@ TEST_F(Lease4Test, decline) { lease.fqdn_rev_ = true; time_t now = time(0); + ElementPtr context = Element::createMap(); + context->set("bogus", Element::create("true")); + lease.setContext(context); // Move lease to declined state and set its valid-lifetime to 123 seconds lease.decline(123);