From e5a0a264b32f3925c22e2dc3fca07f22f1690c28 Mon Sep 17 00:00:00 2001 From: David Garske Date: Wed, 11 Nov 2020 16:25:21 -0800 Subject: [PATCH] Fix for coverity report with possible use of uninitialized value "err" in `WC_ECC_NONBLOCK` case. More fixes for building with `WOLFSSL_NO_MALLOC`. --- wolfcrypt/src/ecc.c | 1 + wolfcrypt/test/test.c | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index d01efdaf7..7d2dad300 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -6359,6 +6359,7 @@ int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash, /* perform blocking call to non-blocking function */ ecc_nb_ctx_t nb_ctx; XMEMSET(&nb_ctx, 0, sizeof(nb_ctx)); + err = NOT_COMPILED_IN; /* set default error */ #endif #ifndef WOLFSSL_SP_NO_256 if (ecc_sets[key->idx].id == ECC_SECP256R1) { diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index caf260b9d..12f041b33 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -21393,7 +21393,7 @@ exit: } #endif /* WOLFSSL_CERT_GEN */ -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) +#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC) /* Test for the wc_ecc_key_new() and wc_ecc_key_free() functions. */ static int ecc_test_allocator(WC_RNG* rng) { @@ -21993,10 +21993,11 @@ static int ecc_test(void) goto done; } #endif -#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) +#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST) && !defined(WOLFSSL_NO_MALLOC) ret = ecc_test_allocator(&rng); if (ret != 0) { printf("ecc_test_allocator failed!: %d\n", ret); + goto done; } #endif @@ -22005,6 +22006,7 @@ static int ecc_test(void) ret = ecc_test_nonblock(&rng); if (ret != 0) { printf("ecc_test_nonblock failed!: %d\n", ret); + goto done; } #endif @@ -22217,7 +22219,8 @@ done: #if defined(USE_CERT_BUFFERS_256) && !defined(WOLFSSL_ATECC508A) && \ !defined(WOLFSSL_ATECC608A) && !defined(NO_ECC256) && \ defined(HAVE_ECC_VERIFY) && defined(HAVE_ECC_SIGN) -static int ecc_test_buffers(void) { +static int ecc_test_buffers(void) +{ size_t bytes; #ifdef WOLFSSL_SMALL_STACK ecc_key *cliKey = (ecc_key *)XMALLOC(sizeof *cliKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);