From: Bernd Edlinger Date: Sun, 10 Dec 2023 14:21:19 +0000 (+0100) Subject: Fix a possible memory leak in ossl_x509_algor_md_to_mgf1 X-Git-Tag: openssl-3.0.13~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dbc819bd36c2dccde58ece3330a6f47434590c57;p=thirdparty%2Fopenssl.git Fix a possible memory leak in ossl_x509_algor_md_to_mgf1 Add a missing check of the return code of X509_ALGOR_set0. otherwise a memory leak may occur. Reviewed-by: Hugo Landau Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/22999) (cherry picked from commit 493d6c9ab37b18b110c977a2bc896f06b18f6065) --- diff --git a/crypto/asn1/x_algor.c b/crypto/asn1/x_algor.c index c0a5f76803e..2c4a8d4b4ee 100644 --- a/crypto/asn1/x_algor.c +++ b/crypto/asn1/x_algor.c @@ -179,7 +179,11 @@ int ossl_x509_algor_md_to_mgf1(X509_ALGOR **palg, const EVP_MD *mgf1md) *palg = X509_ALGOR_new(); if (*palg == NULL) goto err; - X509_ALGOR_set0(*palg, OBJ_nid2obj(NID_mgf1), V_ASN1_SEQUENCE, stmp); + if (!X509_ALGOR_set0(*palg, OBJ_nid2obj(NID_mgf1), V_ASN1_SEQUENCE, stmp)) { + X509_ALGOR_free(*palg); + *palg = NULL; + goto err; + } stmp = NULL; err: ASN1_STRING_free(stmp);