From cd1a50bfb61190f8a98e3cb831616faa34c86993 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Thu, 21 May 2020 11:19:17 -0600 Subject: [PATCH] add additional sanity check on pointer before free --- wolfcrypt/src/rsa.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/src/rsa.c b/wolfcrypt/src/rsa.c index a441b61ba..98251eddc 100644 --- a/wolfcrypt/src/rsa.c +++ b/wolfcrypt/src/rsa.c @@ -1847,11 +1847,15 @@ static int wc_RsaFunctionSync(const byte* in, word32 inLen, byte* out, } if (ret == 0) { - if (XSecure_RsaPrivateDecrypt(&rsa, (u8*)in, inLen, out) != XST_SUCCESS) { + if (XSecure_RsaPrivateDecrypt(&rsa, (u8*)in, inLen, out) != + XST_SUCCESS) { ret = BAD_STATE_E; } } - XFREE(d, key->heap, DYNAMIC_TYPE_PRIVATE_KEY); + + if (d != NULL) { + XFREE(d, key->heap, DYNAMIC_TYPE_PRIVATE_KEY); + } } #endif break;