Skip to content

Commit

Permalink
wolfcrypt test: fix double free.
Browse files Browse the repository at this point in the history
  • Loading branch information
philljj committed Oct 21, 2024
1 parent 35def11 commit 5690af8
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions wolfcrypt/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -33731,6 +33731,8 @@ static wc_test_ret_t ecc_ctx_kdf_salt_test(WC_RNG* rng, ecc_key* a, ecc_key* b)
word32 plaintextLen;
word32 encryptLen = MAX_ECIES_TEST_SZ;
word32 decryptLen = MAX_ECIES_TEST_SZ;
int aInit = 0;
int bInit = 0;

#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
plaintext = XMALLOC(MAX_ECIES_TEST_SZ, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
Expand All @@ -33742,12 +33744,22 @@ static wc_test_ret_t ecc_ctx_kdf_salt_test(WC_RNG* rng, ecc_key* a, ecc_key* b)
wc_ecc_free(b);

ret = wc_ecc_init(a);
if (ret != 0)
if (ret != 0) {
ret = WC_TEST_RET_ENC_EC(ret);
}
else {
aInit = 1;
}


if (ret == 0) {
ret = wc_ecc_init(b);
if (ret != 0)
if (ret != 0) {
ret = WC_TEST_RET_ENC_EC(ret);
}
else {
bInit = 1;
}
}

if (ret == 0)
Expand Down Expand Up @@ -33809,8 +33821,13 @@ static wc_test_ret_t ecc_ctx_kdf_salt_test(WC_RNG* rng, ecc_key* a, ecc_key* b)
if (ret == 0 && XMEMCMP(decrypted, plaintext, plaintextLen) != 0)
ret = WC_TEST_RET_ENC_NC;

wc_ecc_free(a);
wc_ecc_free(b);
if (aInit) {
wc_ecc_free(a);
}

if (bInit) {
wc_ecc_free(b);
}

wc_ecc_ctx_free(aCtx);
wc_ecc_ctx_free(bCtx);
Expand Down

0 comments on commit 5690af8

Please sign in to comment.