dhcp: prevent dhcp_cleanup passing external data to heap

This commit is contained in:
Simon Goldschmidt 2021-03-04 22:20:17 +01:00
parent c7e1b35899
commit 3ff267fbed
2 changed files with 9 additions and 2 deletions

View File

@ -719,6 +719,8 @@ dhcp_set_struct(struct netif *netif, struct dhcp *dhcp)
/* clear data structure */
memset(dhcp, 0, sizeof(struct dhcp));
/* mark this as externally allocated */
dhcp->flags |= DHCP_FLAG_EXTERNAL_MEM;
/* dhcp_set_state(&dhcp, DHCP_STATE_OFF); */
netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, dhcp);
}
@ -734,11 +736,15 @@ dhcp_set_struct(struct netif *netif, struct dhcp *dhcp)
*/
void dhcp_cleanup(struct netif *netif)
{
struct dhcp *dhcp;
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("netif != NULL", netif != NULL);
if (netif_dhcp_data(netif) != NULL) {
mem_free(netif_dhcp_data(netif));
dhcp = netif_dhcp_data(netif);
if (dhcp != NULL) {
if (!(dhcp->flags & DHCP_FLAG_EXTERNAL_MEM)) {
mem_free(dhcp);
}
netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, NULL);
}
}

View File

@ -63,6 +63,7 @@ extern "C" {
#define DHCP_BOOT_FILE_LEN 128U
#define DHCP_FLAG_SUBNET_MASK_GIVEN 0x01
#define DHCP_FLAG_EXTERNAL_MEM 0x02
/* AutoIP cooperation flags (struct dhcp.autoip_coop_state) */
typedef enum {