Skip to content

Commit 04984a5

Browse files
authored
Merge pull request #10346 from Frauschi/ecc_leak_fix
Prevent ECC tmp key leak and UB
2 parents 7e9635d + 0dd6aa3 commit 04984a5

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

wolfcrypt/src/ecc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3733,7 +3733,7 @@ int wc_ecc_mulmod_ex(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
37333733
#endif
37343734
int i, err;
37353735
#ifdef WOLFSSL_SMALL_STACK_CACHE
3736-
ecc_key *key = (ecc_key *)XMALLOC(sizeof(*key), heap, DYNAMIC_TYPE_ECC);
3736+
ecc_key *key = NULL;
37373737
#endif
37383738
mp_digit mp;
37393739

@@ -3753,6 +3753,7 @@ int wc_ecc_mulmod_ex(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
37533753
}
37543754

37553755
#ifdef WOLFSSL_SMALL_STACK_CACHE
3756+
key = (ecc_key *)XMALLOC(sizeof(*key), heap, DYNAMIC_TYPE_ECC);
37563757
if (key == NULL) {
37573758
err = MP_MEM;
37583759
goto exit;
@@ -3815,8 +3816,7 @@ int wc_ecc_mulmod_ex(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
38153816
if (key) {
38163817
if (R)
38173818
R->key = NULL;
3818-
if (err == MP_OKAY)
3819-
ecc_key_tmp_final(key, heap);
3819+
ecc_key_tmp_final(key, heap);
38203820
XFREE(key, heap, DYNAMIC_TYPE_ECC);
38213821
}
38223822
#endif /* WOLFSSL_SMALL_STACK_CACHE */

0 commit comments

Comments
 (0)