mirror of
https://github.com/espressif/esp-idf.git
synced 2024-09-20 00:36:01 -04:00
esp_netif: Fixed possible use of hostname pointer after its freed
When setting hostname using esp_netif_set_hostname_api() failed for some reason, the netif pointer might be freed while lwip pointer stil point to that location and could be used. Fixed by moving the freeing and string duplication to the block where lwip hostname is set. Closes https://github.com/espressif/esp-idf/issues/6048
This commit is contained in:
parent
ae30617810
commit
7c4d3fbf8b
@ -1133,19 +1133,20 @@ static esp_err_t esp_netif_set_hostname_api(esp_netif_api_msg_t *msg)
|
||||
#if LWIP_NETIF_HOSTNAME
|
||||
|
||||
struct netif *p_netif = esp_netif->lwip_netif;
|
||||
if (esp_netif->hostname) {
|
||||
free(esp_netif->hostname);
|
||||
}
|
||||
esp_netif->hostname = strdup(hostname);
|
||||
if (esp_netif->hostname == NULL) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
if (strlen(hostname) > ESP_NETIF_HOSTNAME_MAX_SIZE) {
|
||||
return ESP_ERR_ESP_NETIF_INVALID_PARAMS;
|
||||
}
|
||||
|
||||
if (p_netif != NULL) {
|
||||
if (esp_netif->hostname) {
|
||||
free(esp_netif->hostname);
|
||||
}
|
||||
esp_netif->hostname = strdup(hostname);
|
||||
if (esp_netif->hostname == NULL) {
|
||||
p_netif->hostname = CONFIG_LWIP_LOCAL_HOSTNAME;
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
p_netif->hostname = esp_netif->hostname;
|
||||
return ESP_OK;
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user