Skip to content

Commit

Permalink
Fix a possible memory leak in dane_tlsa_add
Browse files Browse the repository at this point in the history
Several error cases leak either the X509 object
or the pkey or the danetls_record object.

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from #22743)

(cherry picked from commit e4a94bc)
  • Loading branch information
bernd-edlinger authored and levitte committed Nov 22, 2023
1 parent 306abd4 commit 151d15e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ssl/ssl_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,18 +342,21 @@ static int dane_tlsa_add(SSL_DANE *dane,
case DANETLS_SELECTOR_CERT:
if (!d2i_X509(&cert, &p, ilen) || p < data ||
dlen != (size_t)(p - data)) {
X509_free(cert);
tlsa_free(t);
ERR_raise(ERR_LIB_SSL, SSL_R_DANE_TLSA_BAD_CERTIFICATE);
return 0;
}
if (X509_get0_pubkey(cert) == NULL) {
X509_free(cert);
tlsa_free(t);
ERR_raise(ERR_LIB_SSL, SSL_R_DANE_TLSA_BAD_CERTIFICATE);
return 0;
}

if ((DANETLS_USAGE_BIT(usage) & DANETLS_TA_MASK) == 0) {
X509_free(cert);
tlsa_free(t);
break;
}

Expand All @@ -377,6 +380,7 @@ static int dane_tlsa_add(SSL_DANE *dane,
case DANETLS_SELECTOR_SPKI:
if (!d2i_PUBKEY(&pkey, &p, ilen) || p < data ||
dlen != (size_t)(p - data)) {
EVP_PKEY_free(pkey);
tlsa_free(t);
ERR_raise(ERR_LIB_SSL, SSL_R_DANE_TLSA_BAD_PUBLIC_KEY);
return 0;
Expand Down

0 comments on commit 151d15e

Please sign in to comment.