From f7038ab8b9bcd3bb651d7decbfba3744b00a1c81 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Wed, 17 Sep 2008 13:09:30 +0000 Subject: [PATCH] As we now use times to trigger again instead of decreasing timers, ensure our lease fits. We may wish to revisit this again if we need decreasing timers once more. --- dhcp.c | 6 +++--- eloop.c | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/dhcp.c b/dhcp.c index 0aa13fa6..2658e89d 100644 --- a/dhcp.c +++ b/dhcp.c @@ -1252,15 +1252,15 @@ configure_env(char **env, const char *prefix, const struct dhcp_message *dhcp, void get_lease(struct dhcp_lease *lease, const struct dhcp_message *dhcp) { - time_t t; + struct timeval now; lease->addr.s_addr = dhcp->yiaddr; if (get_option_addr(&lease->net.s_addr, dhcp, DHO_SUBNETMASK) == -1) lease->net.s_addr = get_netmask(dhcp->yiaddr); if (get_option_uint32(&lease->leasetime, dhcp, DHO_LEASETIME) == 0) { /* Ensure that we can use the lease */ - t = 0; - if (t + (time_t)lease->leasetime < t) + get_monotonic(&now); + if (now.tv_sec + (time_t)lease->leasetime < now.tv_sec) lease->leasetime = ~0U; /* Infinite lease */ } else lease->leasetime = DEFAULT_LEASETIME; diff --git a/eloop.c b/eloop.c index 8f601349..4b9b6b6a 100644 --- a/eloop.c +++ b/eloop.c @@ -117,6 +117,11 @@ add_timeout_tv(const struct timeval *when, get_monotonic(&now); timeradd(&now, when, &w); + /* Check for time_t overflow. */ + if (timercmp(&w, &now, <)) { + errno = ERANGE; + return; + } /* Remove existing timeout if present */ for (t = timeouts; t; t = t->next) { -- 2.47.3