From 8ce4e126ae3c329a085e70c6d5725e7aeeef12b4 Mon Sep 17 00:00:00 2001 From: Eric Blankenhorn Date: Tue, 5 May 2026 10:23:36 -0500 Subject: [PATCH] Fix from review --- wolfcrypt/test/test.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 2d692f9aca..6cfe52daac 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -52574,16 +52574,21 @@ static wc_test_ret_t dilithium_sign_cache_alloc_test(int param, WC_RNG* rng) key = (dilithium_key*)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, HEAP_HINT, - DYNAMIC_TYPE_TMP_BUFFER); - if (key == NULL || sig == NULL) { + if (key == NULL) { ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); } - + /* Init before further allocations so wc_dilithium_free() in the cleanup + * path operates on a zeroed struct, not garbage cached-pointer fields. */ ret = wc_dilithium_init_ex(key, NULL, devId); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out); + sig = (byte*)XMALLOC(DILITHIUM_MAX_SIG_SIZE, HEAP_HINT, + DYNAMIC_TYPE_TMP_BUFFER); + if (sig == NULL) { + ERROR_OUT(WC_TEST_RET_ENC_ERRNO, out); + } + ret = wc_dilithium_set_level(key, param); if (ret != 0) ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);