From 1e348b991d6b6c941dc3a3018c1d8eb50c73094f Mon Sep 17 00:00:00 2001 From: John Safranek Date: Thu, 12 Nov 2020 11:33:42 -0800 Subject: [PATCH] Scan-Build Fixes 1. Fix a potential dereference of NULL pointer. To recreate: $ scan-build ./configure --enable-sp --enable-sp-asm --enable-sp-math --- wolfcrypt/src/sp_int.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/wolfcrypt/src/sp_int.c b/wolfcrypt/src/sp_int.c index ab1bd6dcc..cc677a481 100644 --- a/wolfcrypt/src/sp_int.c +++ b/wolfcrypt/src/sp_int.c @@ -2321,9 +2321,11 @@ int sp_prime_is_prime_ex(sp_int* a, int t, int* result, WC_RNG* rng) if (a == NULL || result == NULL || rng == NULL) err = MP_VAL; - if (sp_isone(a)) { - *result = MP_NO; - return MP_OKAY; + if (err == MP_OKAY) { + if (sp_isone(a)) { + *result = MP_NO; + return MP_OKAY; + } } if (err == MP_OKAY && a->used == 1) { @@ -2410,7 +2412,8 @@ int sp_prime_is_prime_ex(sp_int* a, int t, int* result, WC_RNG* rng) (void)t; #endif /* !WC_NO_RNG */ - *result = ret; + if (result != NULL) + *result = ret; return err; }