Skip to content

Commit 5690af8

Browse files
committed
wolfcrypt test: fix double free.
1 parent 35def11 commit 5690af8

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

wolfcrypt/test/test.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33731,6 +33731,8 @@ static wc_test_ret_t ecc_ctx_kdf_salt_test(WC_RNG* rng, ecc_key* a, ecc_key* b)
3373133731
word32 plaintextLen;
3373233732
word32 encryptLen = MAX_ECIES_TEST_SZ;
3373333733
word32 decryptLen = MAX_ECIES_TEST_SZ;
33734+
int aInit = 0;
33735+
int bInit = 0;
3373433736

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

3374433746
ret = wc_ecc_init(a);
33745-
if (ret != 0)
33747+
if (ret != 0) {
3374633748
ret = WC_TEST_RET_ENC_EC(ret);
33749+
}
33750+
else {
33751+
aInit = 1;
33752+
}
33753+
33754+
3374733755
if (ret == 0) {
3374833756
ret = wc_ecc_init(b);
33749-
if (ret != 0)
33757+
if (ret != 0) {
3375033758
ret = WC_TEST_RET_ENC_EC(ret);
33759+
}
33760+
else {
33761+
bInit = 1;
33762+
}
3375133763
}
3375233764

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

33812-
wc_ecc_free(a);
33813-
wc_ecc_free(b);
33824+
if (aInit) {
33825+
wc_ecc_free(a);
33826+
}
33827+
33828+
if (bInit) {
33829+
wc_ecc_free(b);
33830+
}
3381433831

3381533832
wc_ecc_ctx_free(aCtx);
3381633833
wc_ecc_ctx_free(bCtx);

0 commit comments

Comments
 (0)