mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-01 03:34:32 +02: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:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user