dhcpv4: fix possible segfault when lease is not created
authorHans Dedecker <dedeckeh@gmail.com>
Thu, 17 Aug 2017 10:16:07 +0000 (12:16 +0200)
committerHans Dedecker <dedeckeh@gmail.com>
Thu, 17 Aug 2017 10:16:38 +0000 (12:16 +0200)
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
src/dhcpv4.c

index db900c138528a861052b972937575561fa2b3b44..c7ac058b5d9396e8ff4a83adca2441d0110f0875 100644 (file)
@@ -587,7 +587,6 @@ static struct dhcpv4_assignment* dhcpv4_lease(struct interface *iface,
 
        if (msg == DHCPV4_MSG_DISCOVER || msg == DHCPV4_MSG_REQUEST) {
                bool assigned = !!a;
-               uint32_t my_leasetime;
 
                if (!a && !iface->no_dynamic_dhcp) {
                        /* Create new binding */
@@ -605,15 +604,17 @@ static struct dhcpv4_assignment* dhcpv4_lease(struct interface *iface,
                                list_add(&a->head, &iface->dhcpv4_assignments);
                }
 
-               if (a->leasetime)
-                       my_leasetime = a->leasetime;
-               else
-                       my_leasetime = iface->dhcpv4_leasetime;
+               if (assigned) {
+                       uint32_t my_leasetime;
 
-               if ((*leasetime == 0) || (my_leasetime < *leasetime))
-                       *leasetime = my_leasetime;
+                       if (a->leasetime)
+                               my_leasetime = a->leasetime;
+                       else
+                               my_leasetime = iface->dhcpv4_leasetime;
+
+                       if ((*leasetime == 0) || (my_leasetime < *leasetime))
+                               *leasetime = my_leasetime;
 
-               if (assigned) {
                        if (msg == DHCPV4_MSG_DISCOVER) {
                                a->flags &= ~OAF_BOUND;