mirror of
https://github.com/pi-hole/dnsmasq.git
synced 2025-12-19 18:28:25 +00:00
Handle time_t wraparound more sanely.
This commit is contained in:
21
src/lease.c
21
src/lease.c
@@ -306,7 +306,7 @@ void lease_update_file(time_t now)
|
||||
file_dirty = 0;
|
||||
}
|
||||
|
||||
/* Set alarm for when the first lease expires + slop. */
|
||||
/* Set alarm for when the first lease expires. */
|
||||
next_event = 0;
|
||||
|
||||
#ifdef HAVE_DHCP6
|
||||
@@ -331,8 +331,8 @@ void lease_update_file(time_t now)
|
||||
|
||||
for (lease = leases; lease; lease = lease->next)
|
||||
if (lease->expires != 0 &&
|
||||
(next_event == 0 || difftime(next_event, lease->expires + 10) > 0.0))
|
||||
next_event = lease->expires + 10;
|
||||
(next_event == 0 || difftime(next_event, lease->expires) > 0.0))
|
||||
next_event = lease->expires;
|
||||
|
||||
if (err)
|
||||
{
|
||||
@@ -745,14 +745,23 @@ struct dhcp_lease *lease6_allocate(struct in6_addr *addrp, int lease_type)
|
||||
|
||||
void lease_set_expires(struct dhcp_lease *lease, unsigned int len, time_t now)
|
||||
{
|
||||
time_t exp = now + (time_t)len;
|
||||
|
||||
time_t exp;
|
||||
|
||||
if (len == 0xffffffff)
|
||||
{
|
||||
exp = 0;
|
||||
len = 0;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
exp = now + (time_t)len;
|
||||
/* Check for 2038 overflow. Make the lease
|
||||
inifinite in that case, as the least disruptive
|
||||
thing we can do. */
|
||||
if (difftime(exp, now) <= 0.0)
|
||||
exp = 0;
|
||||
}
|
||||
|
||||
if (exp != lease->expires)
|
||||
{
|
||||
dns_dirty = 1;
|
||||
|
||||
Reference in New Issue
Block a user