Skip to content

Commit

Permalink
Fix memory leak in ossl_rsa_fromdata.
Browse files Browse the repository at this point in the history
Occurs if a malloc failure happens inside collect_numbers()

Reported via #18365

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #18646)

(cherry picked from commit 28adea9)
  • Loading branch information
slontis authored and t8m committed Jun 28, 2022
1 parent 23b7dd6 commit a99b372
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions crypto/rsa/rsa_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ static int collect_numbers(STACK_OF(BIGNUM) *numbers,
if (p != NULL) {
BIGNUM *tmp = NULL;

if (!OSSL_PARAM_get_BN(p, &tmp)
|| sk_BIGNUM_push(numbers, tmp) == 0)
if (!OSSL_PARAM_get_BN(p, &tmp))
return 0;
if (sk_BIGNUM_push(numbers, tmp) == 0) {
BN_clear_free(tmp);
return 0;
}
}
}

Expand Down

0 comments on commit a99b372

Please sign in to comment.