From 3ea4e35737888ed3a92cc0bb5926647e83748c4f Mon Sep 17 00:00:00 2001 From: Marco Oliverio Date: Wed, 10 Nov 2021 11:44:30 +0100 Subject: [PATCH] woflcrypt/src/rsa.c: check memory allocation return value --- wolfcrypt/src/rsa.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/src/rsa.c b/wolfcrypt/src/rsa.c index 2849cfe57..9c66e00d2 100644 --- a/wolfcrypt/src/rsa.c +++ b/wolfcrypt/src/rsa.c @@ -2882,7 +2882,7 @@ int wc_RsaFunction(const byte* in, word32 inLen, byte* out, ret = MEMORY_E; #endif - if (mp_init(c) != MP_OKAY) + if (ret == 0 && mp_init(c) != MP_OKAY) ret = MP_INIT_E; if (ret == 0) { if (mp_read_unsigned_bin(c, in, inLen) != 0) @@ -2906,7 +2906,8 @@ int wc_RsaFunction(const byte* in, word32 inLen, byte* out, mp_clear(c); #ifdef WOLFSSL_SMALL_STACK - XFREE(c, key->heap, DYNAMIC_TYPE_RSA); + if (c != NULL) + XFREE(c, key->heap, DYNAMIC_TYPE_RSA); #endif if (ret != 0) {