Commit 0dd6aa3
committed
Prevent ECC tmp key leak and UB in wc_ecc_mulmod_ex
ecc_key_tmp_final was guarded by `if (err == MP_OKAY)`, leaking
key->t1/t2 (and x/y/z under ALT_ECC_SIZE) whenever an allocation or
mulmod step after ecc_key_tmp_init failed.
Simply removing the guard is unsafe here: unlike wc_ecc_mulmod_ex2
(whose arg checks `return` directly), this function XMALLOC'd `key`
before the arg checks and used `goto exit`, so a bad-arg call would
hand uninitialized memory to ecc_key_tmp_final and XFREE garbage
pointers.
Defer the XMALLOC until after the arg/range checks so `key` is NULL
on the early-error paths, then call ecc_key_tmp_final unconditionally
to plug the leak on the late-error paths.1 parent d7a34d4 commit 0dd6aa3
1 file changed
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3733 | 3733 | | |
3734 | 3734 | | |
3735 | 3735 | | |
3736 | | - | |
| 3736 | + | |
3737 | 3737 | | |
3738 | 3738 | | |
3739 | 3739 | | |
| |||
3753 | 3753 | | |
3754 | 3754 | | |
3755 | 3755 | | |
| 3756 | + | |
3756 | 3757 | | |
3757 | 3758 | | |
3758 | 3759 | | |
| |||
3815 | 3816 | | |
3816 | 3817 | | |
3817 | 3818 | | |
3818 | | - | |
3819 | | - | |
| 3819 | + | |
3820 | 3820 | | |
3821 | 3821 | | |
3822 | 3822 | | |
| |||
0 commit comments