From bc2ae212cf2575a219d23a74cd0867a9df2f733a Mon Sep 17 00:00:00 2001 From: Mahavir Jain Date: Mon, 20 May 2024 12:28:31 +0530 Subject: [PATCH] fix(ecc_alt): adjust null pointer check to fix coverity warning --- components/mbedtls/port/ecc/ecc_alt.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/components/mbedtls/port/ecc/ecc_alt.c b/components/mbedtls/port/ecc/ecc_alt.c index ef0b76fe05..4ffa065c24 100644 --- a/components/mbedtls/port/ecc/ecc_alt.c +++ b/components/mbedtls/port/ecc/ecc_alt.c @@ -81,6 +81,10 @@ int mbedtls_ecp_check_pubkey( const mbedtls_ecp_group *grp, int res; ecc_point_t point; + if (grp == NULL || pt == NULL) { + return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; + } + if (grp->id != MBEDTLS_ECP_DP_SECP192R1 && grp->id != MBEDTLS_ECP_DP_SECP256R1) { #if defined(MBEDTLS_ECP_VERIFY_ALT_SOFT_FALLBACK) return mbedtls_ecp_check_pubkey_soft(grp, pt); @@ -89,13 +93,10 @@ int mbedtls_ecp_check_pubkey( const mbedtls_ecp_group *grp, #endif } - if (grp == NULL || pt == NULL) { - return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; - } - /* Must use affine coordinates */ - if( mbedtls_mpi_cmp_int( &pt->MBEDTLS_PRIVATE(Z), 1 ) != 0 ) + if (mbedtls_mpi_cmp_int( &pt->MBEDTLS_PRIVATE(Z), 1 ) != 0 ) { return( MBEDTLS_ERR_ECP_INVALID_KEY ); + } mbedtls_platform_zeroize((void *)&point, sizeof(ecc_point_t));