Fix Small Memory Leaks

Found with the configuration running the unit test through valgrind.

    % ./configure CFLAGS=-DNO_WOLFSSL_CIPHER_SUITE_TEST \
      --enable-all --disable-fastmath --enable-debug --disable-shared

1. ssl.c: In wolfSSL_DSA_generate_key(), we initialize (and allocate)
   all the parameters in the key (p, q, g, x, y), and then we generate a
   key, initializes (and allocates) x and y, again. mp_clear them
   first.
2. evp.c: When printing public keys, the temporary mp_int wasn't getting
   correctly freed.
3. evp.c: When printing public keys, modified the utility functions to
   return once with a do-while-0 loop.
This commit is contained in:
John Safranek
2022-02-18 10:01:49 -08:00
parent 4b0c8c07f4
commit 041d300b2b
2 changed files with 393 additions and 365 deletions

View File

@@ -34947,6 +34947,12 @@ int wolfSSL_DSA_generate_key(WOLFSSL_DSA* dsa)
}
if (rng) {
/* These were allocated above by SetDsaInternal(). They should
* be cleared before wc_MakeDsaKey() which reinitializes
* x and y. */
mp_clear(&((DsaKey*)dsa->internal)->x);
mp_clear(&((DsaKey*)dsa->internal)->y);
if (wc_MakeDsaKey(rng, (DsaKey*)dsa->internal) != MP_OKAY)
WOLFSSL_MSG("wc_MakeDsaKey failed");
else if (SetDsaExternal(dsa) != WOLFSSL_SUCCESS)