From: Hans Dedecker Date: Thu, 17 Aug 2017 10:16:07 +0000 (+0200) Subject: dhcpv4: fix possible segfault when lease is not created X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=1a313f9052e315571f42e9888d7bc8e443c5bb56;p=project%2Fodhcpd.git dhcpv4: fix possible segfault when lease is not created Signed-off-by: Hans Dedecker --- diff --git a/src/dhcpv4.c b/src/dhcpv4.c index db900c1..c7ac058 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -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;