Merge branch 'fix/esp_netif-oom-null-checks-v5.5_v5.3' into 'release/v5.3'

fix(esp_netif): harden NULL and OOM handling in netif APIs (SEC-1189, SEC-1190) (v5.3)

See merge request espressif/esp-idf!50785
This commit is contained in:
Euripedes Rocha
2026-08-04 12:34:24 +02:00
2 changed files with 15 additions and 6 deletions
+11 -6
View File
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -333,12 +333,17 @@ esp_err_t esp_netif_br_glue_add_port(esp_netif_br_glue_handle_t netif_br_glue, e
{
if (netif_br_glue->ports_esp_netifs == NULL) {
netif_br_glue->ports_esp_netifs = malloc(sizeof(esp_netif_t *));
if (netif_br_glue->ports_esp_netifs == NULL) {
ESP_LOGE(TAG, "no memory to add br port");
return ESP_ERR_NO_MEM;
}
} else {
netif_br_glue->ports_esp_netifs = realloc(netif_br_glue->ports_esp_netifs, (netif_br_glue->port_cnt + 1) * sizeof(esp_netif_t *));
}
if (!netif_br_glue->ports_esp_netifs) {
ESP_LOGE(TAG, "no memory to add br port");
return ESP_ERR_NO_MEM;
esp_netif_t **new_ports = realloc(netif_br_glue->ports_esp_netifs, (netif_br_glue->port_cnt + 1) * sizeof(esp_netif_t *));
if (new_ports == NULL) {
ESP_LOGE(TAG, "no memory to add br port");
return ESP_ERR_NO_MEM;
}
netif_br_glue->ports_esp_netifs = new_ports;
}
netif_br_glue->ports_esp_netifs[netif_br_glue->port_cnt] = esp_netif_port;
@@ -712,6 +712,7 @@ static esp_err_t esp_netif_new_api(esp_netif_api_msg_t *msg)
const esp_netif_config_t *esp_netif_config = msg->data;
// mandatory configuration must be provided when creating esp_netif object
if (esp_netif_config == NULL ||
esp_netif_config->base == NULL ||
esp_netif_config->base->if_key == NULL ||
NULL != esp_netif_get_handle_from_ifkey_unsafe(esp_netif_config->base->if_key)) {
ESP_LOGE(TAG, "%s: Failed to configure netif with config=%p (config or if_key is NULL or duplicate key)",
@@ -1021,6 +1022,9 @@ esp_err_t esp_netif_set_mac_api(esp_netif_api_msg_t *msg)
esp_err_t esp_netif_set_mac(esp_netif_t *esp_netif, uint8_t mac[])
{
if (mac == NULL) {
return ESP_ERR_INVALID_ARG;
}
if (esp_netif == NULL || esp_netif->lwip_netif == NULL) {
return ESP_ERR_ESP_NETIF_IF_NOT_READY;
}