fix(wpa_supplicant): Fix some coverity issues in wpa_supplicant

1. Fix leak in SoftAP while sending SAE Confirm
2. Move NULL check before pointer is getting used
3. Remove some dead code
This commit is contained in:
Nachiket Kukade
2024-12-30 11:50:03 +05:30
committed by Shreyas Sheth
parent 9795558c03
commit 2d913cbd01
3 changed files with 7 additions and 4 deletions

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -1151,6 +1151,10 @@ struct wpabuf * crypto_ecdh_set_peerkey(struct crypto_ecdh *ecdh, int inc_y,
int secret_key = 0; int secret_key = 0;
mbedtls_ecdh_context *ctx = (mbedtls_ecdh_context *)ecdh; mbedtls_ecdh_context *ctx = (mbedtls_ecdh_context *)ecdh;
if (!ctx) {
wpa_printf(MSG_ERROR, "ECDH Context is NULL");
return 0;
}
mbedtls_ctr_drbg_context ctr_drbg; mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_entropy_context entropy; mbedtls_entropy_context entropy;
@ -1205,7 +1209,7 @@ struct wpabuf * crypto_ecdh_set_peerkey(struct crypto_ecdh *ecdh, int inc_y,
/* Setup ECDH context from EC key */ /* Setup ECDH context from EC key */
/* Call to mbedtls_ecdh_get_params() will initialize the context when not LEGACY context */ /* Call to mbedtls_ecdh_get_params() will initialize the context when not LEGACY context */
if (ctx != NULL && peer != NULL) { if (peer != NULL) {
mbedtls_ecp_copy( ACCESS_ECDH(&ctx, Qp), &(mbedtls_pk_ec(*peer))->MBEDTLS_PRIVATE(Q) ); mbedtls_ecp_copy( ACCESS_ECDH(&ctx, Qp), &(mbedtls_pk_ec(*peer))->MBEDTLS_PRIVATE(Q) );
#ifndef CONFIG_MBEDTLS_ECDH_LEGACY_CONTEXT #ifndef CONFIG_MBEDTLS_ECDH_LEGACY_CONTEXT
ctx->MBEDTLS_PRIVATE(var) = MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0; ctx->MBEDTLS_PRIVATE(var) = MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0;

View File

@ -178,6 +178,7 @@ static int auth_sae_send_confirm(struct hostapd_data *hapd,
#ifdef ESP_SUPPLICANT #ifdef ESP_SUPPLICANT
if (sta->remove_pending) { if (sta->remove_pending) {
reply_res = -1; reply_res = -1;
wpabuf_free(data);
} else { } else {
if (sta->sae_data) if (sta->sae_data)
wpabuf_free(sta->sae_data); wpabuf_free(sta->sae_data);

View File

@ -2718,8 +2718,6 @@ struct wpa_sm * get_wpa_sm(void)
int wpa_sm_set_ap_rsnxe(const u8 *ie, size_t len) int wpa_sm_set_ap_rsnxe(const u8 *ie, size_t len)
{ {
struct wpa_sm *sm = &gWpaSm; struct wpa_sm *sm = &gWpaSm;
if (!sm)
return -1;
os_free(sm->ap_rsnxe); os_free(sm->ap_rsnxe);
if (!ie || len == 0) { if (!ie || len == 0) {