From e995568626b2f5252b033016d0b9b8806b653da9 Mon Sep 17 00:00:00 2001 From: Kareem Date: Thu, 6 Jul 2023 21:07:36 -0700 Subject: [PATCH 1/3] Fixed crash in wc_ecc_free. --- wolfcrypt/src/ecc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index 359bcee76..dbe762c06 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -7654,7 +7654,8 @@ int wc_ecc_free(ecc_key* key) mp_clear(key->pubkey.y); mp_clear(key->pubkey.z); - mp_forcezero(key->k); + if (key->k) + mp_forcezero(key->k); #ifdef WOLFSSL_CUSTOM_CURVES if (key->deallocSet && key->dp != NULL) From 657679efda29e24610d73b55514cea55a6f27965 Mon Sep 17 00:00:00 2001 From: Kareem Date: Thu, 6 Jul 2023 21:15:37 -0700 Subject: [PATCH 2/3] Only check for ALT_ECC_SIZE case, otherwise key->k is an array which will never be NULL. --- wolfcrypt/src/ecc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index dbe762c06..9124234c9 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -7654,7 +7654,9 @@ int wc_ecc_free(ecc_key* key) mp_clear(key->pubkey.y); mp_clear(key->pubkey.z); +#ifdef ALT_ECC_SIZE if (key->k) +#endif mp_forcezero(key->k); #ifdef WOLFSSL_CUSTOM_CURVES From fb9e036d5bbf4aad99930b92a388fe306560a7a5 Mon Sep 17 00:00:00 2001 From: Kareem Date: Thu, 6 Jul 2023 14:47:18 -0700 Subject: [PATCH 3/3] Add NULL check in TFM's fp_forcezero. --- wolfcrypt/src/tfm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wolfcrypt/src/tfm.c b/wolfcrypt/src/tfm.c index 4c1fa9aac..b4a224a05 100644 --- a/wolfcrypt/src/tfm.c +++ b/wolfcrypt/src/tfm.c @@ -4398,6 +4398,9 @@ void fp_clear(fp_int *a) void fp_forcezero (mp_int * a) { + if (a == NULL) + return; + int size; a->used = 0; a->sign = FP_ZPOS;