]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
As we now use times to trigger again instead of decreasing timers, ensure our lease...
authorRoy Marples <roy@marples.name>
Wed, 17 Sep 2008 13:09:30 +0000 (13:09 +0000)
committerRoy Marples <roy@marples.name>
Wed, 17 Sep 2008 13:09:30 +0000 (13:09 +0000)
dhcp.c
eloop.c

diff --git a/dhcp.c b/dhcp.c
index 0aa13fa6366371841f75b33fd7e517b010b36b3b..2658e89db457534e016f241e4a7a5dd00a85f7c1 100644 (file)
--- 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 8f60134939b38a5fb0616c9994508111a7cdcf7d..4b9b6b6a98470f6f53ee1dae2a1d51987b6607e3 100644 (file)
--- 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) {