mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-30 10:47:28 +02:00
Fixes for several memory leaks related to HAVE_WOLF_BIGINT
.
This commit is contained in:
@ -36407,6 +36407,7 @@ int wolfSSL_DH_LoadDer(WOLFSSL_DH* dh, const unsigned char* derBuf, int derSz)
|
|||||||
WOLFSSL_MSG("wc_DhKeyDecode failed");
|
WOLFSSL_MSG("wc_DhKeyDecode failed");
|
||||||
return WOLFSSL_FATAL_ERROR;
|
return WOLFSSL_FATAL_ERROR;
|
||||||
}
|
}
|
||||||
|
dh->inSet = 1;
|
||||||
|
|
||||||
if (SetDhExternal(dh) != WOLFSSL_SUCCESS) {
|
if (SetDhExternal(dh) != WOLFSSL_SUCCESS) {
|
||||||
WOLFSSL_MSG("SetDhExternal failed");
|
WOLFSSL_MSG("SetDhExternal failed");
|
||||||
|
25
tests/api.c
25
tests/api.c
@ -1271,6 +1271,7 @@ static void test_wolfSSL_CertManagerNameConstraint(void)
|
|||||||
|
|
||||||
XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
XFREE(der, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
||||||
wolfSSL_X509_free(x509);
|
wolfSSL_X509_free(x509);
|
||||||
|
wc_FreeRsaKey(&key);
|
||||||
wc_FreeRng(&rng);
|
wc_FreeRng(&rng);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -28357,27 +28358,30 @@ static int test_wolfSSL_GetLoggingCb (void)
|
|||||||
#ifdef DEBUG_WOLFSSL
|
#ifdef DEBUG_WOLFSSL
|
||||||
printf(testingFmt, "wolfSSL_GetLoggingCb()");
|
printf(testingFmt, "wolfSSL_GetLoggingCb()");
|
||||||
|
|
||||||
/*Testing without wolfSSL_SetLoggingCb()*/
|
/* Testing without wolfSSL_SetLoggingCb() */
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
if(wolfSSL_GetLoggingCb() == NULL){ /*Should be true*/
|
if (wolfSSL_GetLoggingCb() == NULL) { /* Should be true */
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
if(wolfSSL_GetLoggingCb() != NULL){ /*Should not be true*/
|
if (wolfSSL_GetLoggingCb() != NULL) { /* Should not be true */
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*Testing with wolfSSL_SetLoggingCb()*/
|
/* Testing with wolfSSL_SetLoggingCb() */
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
ret = wolfSSL_SetLoggingCb(Logging_cb);
|
ret = wolfSSL_SetLoggingCb(Logging_cb);
|
||||||
if (ret == 0){
|
if (ret == 0){
|
||||||
if(wolfSSL_GetLoggingCb() == NULL){ /*Should not be true*/
|
if (wolfSSL_GetLoggingCb() == NULL) { /* Should not be true */
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
if(wolfSSL_GetLoggingCb() == Logging_cb){ /*Should be true*/
|
if (wolfSSL_GetLoggingCb() == Logging_cb) { /* Should be true */
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* reset logging callback */
|
||||||
|
wolfSSL_SetLoggingCb(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf(resultFmt, ret == 0 ? passed : failed);
|
printf(resultFmt, ret == 0 ? passed : failed);
|
||||||
@ -31560,16 +31564,11 @@ static void test_wolfSSL_EC_KEY_dup(void)
|
|||||||
/* NULL private key */
|
/* NULL private key */
|
||||||
AssertNotNull(ecKey = wolfSSL_EC_KEY_new());
|
AssertNotNull(ecKey = wolfSSL_EC_KEY_new());
|
||||||
AssertIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
|
AssertIntEQ(wolfSSL_EC_KEY_generate_key(ecKey), 1);
|
||||||
#if defined(WOLFSSL_PUBLIC_MP)
|
|
||||||
mp_int* mp = (mp_int*)ecKey->priv_key->internal;
|
|
||||||
mp_forcezero(mp);
|
|
||||||
mp_free(mp);
|
|
||||||
ecKey->priv_key->internal = NULL; /* Set internal key to NULL */
|
|
||||||
AssertNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
|
|
||||||
#endif
|
|
||||||
wolfSSL_BN_free(ecKey->priv_key);
|
wolfSSL_BN_free(ecKey->priv_key);
|
||||||
ecKey->priv_key = NULL; /* Set priv_key to NULL */
|
ecKey->priv_key = NULL; /* Set priv_key to NULL */
|
||||||
AssertNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
|
AssertNull(dupKey = wolfSSL_EC_KEY_dup(ecKey));
|
||||||
|
|
||||||
wolfSSL_EC_KEY_free(ecKey);
|
wolfSSL_EC_KEY_free(ecKey);
|
||||||
wolfSSL_EC_KEY_free(dupKey);
|
wolfSSL_EC_KEY_free(dupKey);
|
||||||
|
|
||||||
|
@ -6919,7 +6919,7 @@ int wc_GmacVerify(const byte* key, word32 keySz,
|
|||||||
const byte* authTag, word32 authTagSz)
|
const byte* authTag, word32 authTagSz)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
#ifndef NO_AES_DECRYPT
|
#ifdef HAVE_AES_DECRYPT
|
||||||
Aes aes;
|
Aes aes;
|
||||||
|
|
||||||
if (key == NULL || iv == NULL || (authIn == NULL && authInSz != 0) ||
|
if (key == NULL || iv == NULL || (authIn == NULL && authInSz != 0) ||
|
||||||
|
@ -1346,9 +1346,12 @@ static int wc_ecc_curve_cache_load_item(ecc_curve_spec* curve, const char* src,
|
|||||||
static int wc_ecc_curve_load(const ecc_set_type* dp, ecc_curve_spec** pCurve,
|
static int wc_ecc_curve_load(const ecc_set_type* dp, ecc_curve_spec** pCurve,
|
||||||
byte load_mask)
|
byte load_mask)
|
||||||
{
|
{
|
||||||
int ret = 0, x;
|
int ret = 0;
|
||||||
ecc_curve_spec* curve;
|
ecc_curve_spec* curve;
|
||||||
byte load_items = 0; /* mask of items to load */
|
byte load_items = 0; /* mask of items to load */
|
||||||
|
#ifdef ECC_CACHE_CURVE
|
||||||
|
int x;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (dp == NULL || pCurve == NULL)
|
if (dp == NULL || pCurve == NULL)
|
||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
|
@ -151,7 +151,20 @@ int sp_init_multi(sp_int* a, sp_int* b, sp_int* c, sp_int* d, sp_int* e,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Clear the data from the big number and set to zero.
|
/* Free the memory from the big number.
|
||||||
|
*
|
||||||
|
* a SP integer.
|
||||||
|
*/
|
||||||
|
void sp_free(sp_int* a)
|
||||||
|
{
|
||||||
|
if (a != NULL) {
|
||||||
|
#ifdef HAVE_WOLF_BIGINT
|
||||||
|
wc_bigint_free(&a->raw);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Clear and Free the data from the big number and set to zero.
|
||||||
*
|
*
|
||||||
* a SP integer.
|
* a SP integer.
|
||||||
*/
|
*/
|
||||||
@ -163,6 +176,8 @@ void sp_clear(sp_int* a)
|
|||||||
for (i=0; i<a->used; i++)
|
for (i=0; i<a->used; i++)
|
||||||
a->dp[i] = 0;
|
a->dp[i] = 0;
|
||||||
a->used = 0;
|
a->used = 0;
|
||||||
|
|
||||||
|
sp_free(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -911,7 +911,7 @@
|
|||||||
#define BUILD_DES3
|
#define BUILD_DES3
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(NO_AES) || defined(NO_AES_DECRYPT)
|
#if defined(NO_AES) || !defined(HAVE_AES_DECRYPT)
|
||||||
#define AES_BLOCK_SIZE 16
|
#define AES_BLOCK_SIZE 16
|
||||||
#undef BUILD_AES
|
#undef BUILD_AES
|
||||||
#else
|
#else
|
||||||
|
@ -189,6 +189,7 @@ typedef sp_int_digit mp_digit;
|
|||||||
MP_API int sp_init(sp_int* a);
|
MP_API int sp_init(sp_int* a);
|
||||||
MP_API int sp_init_multi(sp_int* a, sp_int* b, sp_int* c, sp_int* d,
|
MP_API int sp_init_multi(sp_int* a, sp_int* b, sp_int* c, sp_int* d,
|
||||||
sp_int* e, sp_int* f);
|
sp_int* e, sp_int* f);
|
||||||
|
MP_API void sp_free(sp_int* a);
|
||||||
MP_API void sp_clear(sp_int* a);
|
MP_API void sp_clear(sp_int* a);
|
||||||
MP_API int sp_unsigned_bin_size(sp_int* a);
|
MP_API int sp_unsigned_bin_size(sp_int* a);
|
||||||
MP_API int sp_read_unsigned_bin(sp_int* a, const byte* in, word32 inSz);
|
MP_API int sp_read_unsigned_bin(sp_int* a, const byte* in, word32 inSz);
|
||||||
@ -250,7 +251,7 @@ MP_API int sp_mul_d(sp_int* a, sp_int_digit n, sp_int* r);
|
|||||||
|
|
||||||
#define CheckFastMathSettings() 1
|
#define CheckFastMathSettings() 1
|
||||||
|
|
||||||
#define mp_free(a)
|
#define mp_free(a) sp_free
|
||||||
|
|
||||||
#define mp_isodd sp_isodd
|
#define mp_isodd sp_isodd
|
||||||
#define mp_iseven sp_iseven
|
#define mp_iseven sp_iseven
|
||||||
|
Reference in New Issue
Block a user