From d73efd7d3874261c5781c1cabcc2b504cc4b6619 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 5 Jul 2018 21:39:00 +0800 Subject: [PATCH] dhcp: Prevent NULL pointer dereference in dhcp_select Move the code to make sure netif is not NULL before calling netif_dhcp_data(netif). Signed-off-by: Axel Lin --- src/core/ipv4/dhcp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index 3946b63b..18b809e2 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -365,7 +365,7 @@ dhcp_handle_offer(struct netif *netif, struct dhcp_msg *msg_in) static err_t dhcp_select(struct netif *netif) { - struct dhcp *dhcp = netif_dhcp_data(netif); + struct dhcp *dhcp; err_t result; u16_t msecs; u8_t i; @@ -373,6 +373,7 @@ dhcp_select(struct netif *netif) u16_t options_out_len; LWIP_ERROR("dhcp_select: netif != NULL", (netif != NULL), return ERR_ARG;); + dhcp = netif_dhcp_data(netif); LWIP_ERROR("dhcp_select: dhcp != NULL", (dhcp != NULL), return ERR_VAL;); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_select(netif=%p) %c%c%"U16_F"\n", (void *)netif, netif->name[0], netif->name[1], (u16_t)netif->num));