From 263cb5bf7890f0ede0671828c0f2b6145c999d9d Mon Sep 17 00:00:00 2001 From: Daniel Pouzzner Date: Wed, 18 Sep 2024 17:42:05 -0500 Subject: [PATCH] tests/api.c:test_Sha512_Family_Final(): fix unreachable null pointer deref reported by clang-tidy in FIPS/Async configs. --- tests/api.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/api.c b/tests/api.c index 2c7804d62f..6b85c7886e 100644 --- a/tests/api.c +++ b/tests/api.c @@ -15007,14 +15007,20 @@ static int test_Sha512_Family_Final(int type, int isRaw) hash_test[2] = hash3; times = sizeof(hash_test) / sizeof(byte *); - /* Good test args. */ - for (i = 0; i < times; i++) { - ExpectIntEQ(finalFp(&sha512, hash_test[i]), 0); +#if defined(HAVE_FIPS) || defined(HAVE_SELFTEST) || \ + defined(WOLFSSL_NO_HASH_RAW) + if (finalFp != NULL) +#endif + { + /* Good test args. */ + for (i = 0; i < times; i++) { + ExpectIntEQ(finalFp(&sha512, hash_test[i]), 0); + } + /* Test bad args. */ + ExpectIntEQ(finalFp(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(finalFp(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); + ExpectIntEQ(finalFp(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); } - /* Test bad args. */ - ExpectIntEQ(finalFp(NULL, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(finalFp(NULL, hash1), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); - ExpectIntEQ(finalFp(&sha512, NULL), WC_NO_ERR_TRACE(BAD_FUNC_ARG)); freeFp(&sha512);