Skip to content

Commit db62bed

Browse files
ejohnstownpadelsbach
authored andcommitted
Free ECC key on ParseECCPubKey error paths
Set keyAllocated right after wc_ecc_init_ex so FreePubKey frees the initialized key on the early error exits, not only after a successful import.
1 parent 85fc81b commit db62bed

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/internal.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5067,6 +5067,11 @@ static int ParseECCPubKey(WOLFSSH *ssh,
50675067

50685068
ret = wc_ecc_init_ex(&sigKeyBlock_ptr->sk.ecc.key, ssh->ctx->heap,
50695069
INVALID_DEVID);
5070+
if (ret == 0) {
5071+
/* The key is initialized. Mark it so that FreePubKey() cleans
5072+
* it up on all paths, including the error paths below. */
5073+
sigKeyBlock_ptr->keyAllocated = 1;
5074+
}
50705075
#ifdef HAVE_WC_ECC_SET_RNG
50715076
if (ret == 0)
50725077
ret = wc_ecc_set_rng(&sigKeyBlock_ptr->sk.ecc.key, ssh->rng);
@@ -5135,7 +5140,6 @@ static int ParseECCPubKey(WOLFSSH *ssh,
51355140
if (ret == 0) {
51365141
sigKeyBlock_ptr->keySz =
51375142
(word32)sizeof(sigKeyBlock_ptr->sk.ecc.key);
5138-
sigKeyBlock_ptr->keyAllocated = 1;
51395143
}
51405144
else {
51415145
ret = WS_ECC_E;

0 commit comments

Comments
 (0)