Merge branch 'fix/sec-1162-1189-1190-null-checks_v6.1' into 'release/v6.1'

fix(esp_netif): harden NULL and OOM handling in netif APIs (SEC-1162, SEC-1189, SEC-1190) (v6.1)

See merge request espressif/esp-idf!50598
This commit is contained in:
Jiang Jiang Jian
2026-09-02 20:11:33 +08:00
2 changed files with 9 additions and 4 deletions

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
*/
@@ -328,12 +328,13 @@ 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 {
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) {
free(netif_br_glue->ports_esp_netifs);
netif_br_glue->ports_esp_netifs = NULL;
netif_br_glue->port_cnt = 0;
ESP_LOGE(TAG, "no memory to add br port");
return ESP_ERR_NO_MEM;
}

View File

@@ -801,6 +801,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)",
@@ -1146,6 +1147,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;
}