From 21f8fe764fbac60de0fe9e970921240f0e41031c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Frauenschl=C3=A4ger?= Date: Wed, 4 Feb 2026 17:51:11 +0100 Subject: [PATCH] Fix Memory leak in CMAC DMA code --- .gitignore | 1 + src/wh_client_crypto.c | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 37f572851..3da946797 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ tools/testcertgen/*.der *.code-workspace .vscode compile_commands.json +**/.cache # Static analysis tools/static-analysis/reports/ diff --git a/src/wh_client_crypto.c b/src/wh_client_crypto.c index c11b931ac..309e951e0 100644 --- a/src/wh_client_crypto.c +++ b/src/wh_client_crypto.c @@ -3838,8 +3838,12 @@ int wh_Client_CmacDma(whClientContext* ctx, Cmac* cmac, CmacType type, /* If this is just a deferred initialization (NULL key, but keyId set), * don't send a request - server will initialize on first update */ if ((key == NULL) && (in == NULL) && (outMac == NULL)) { - /* Just a keyId set operation, nothing to do via DMA */ - return 0; + /* Just a keyId set operation, nothing to do via DMA except for + * cleanup of the state buffer */ + (void)wh_Client_DmaProcessClientAddress( + ctx, (uintptr_t)cmac, (void**)&stateAddr, req->state.sz, + WH_DMA_OPER_CLIENT_WRITE_POST, (whDmaFlags){0}); + return WH_ERROR_OK; } if (ret == WH_ERROR_OK) {