This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit 76ce116487de3081aa2fd54063c425a7c5e5faf1
Author: makejian <[email protected]>
AuthorDate: Tue Nov 10 17:57:43 2026 +0800

    crypto/mbedtls: free the cryptodev resources when cmac update fails
    
    mbedtls_cipher_cmac_update() returns on a cryptodev_crypt() failure
    without releasing the session and the context device, leaking both.
    Add the missing cryptodev_free_session() and cryptodev_free() calls on
    that error path. The finish path already releases both on every path,
    and the cmac context memory is left to mbedtls_cipher_free(), so no
    double free is introduced.
    
    Signed-off-by: makejian <[email protected]>
---
 crypto/mbedtls/source/cmac_alt.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/crypto/mbedtls/source/cmac_alt.c b/crypto/mbedtls/source/cmac_alt.c
index c17d4ebdc..f00f868e3 100644
--- a/crypto/mbedtls/source/cmac_alt.c
+++ b/crypto/mbedtls/source/cmac_alt.c
@@ -109,6 +109,8 @@ int mbedtls_cipher_cmac_update(FAR mbedtls_cipher_context_t 
*ctx,
   ctx->cmac_ctx->dev.crypt.len = ilen;
   if (cryptodev_crypt(&ctx->cmac_ctx->dev) != 0)
     {
+      cryptodev_free_session(&ctx->cmac_ctx->dev);
+      cryptodev_free(&ctx->cmac_ctx->dev);
       return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
     }
 

Reply via email to