From dbc819bd36c2dccde58ece3330a6f47434590c57 Mon Sep 17 00:00:00 2001 From: Bernd Edlinger Date: Sun, 10 Dec 2023 15:21:19 +0100 Subject: [PATCH] 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) --- crypto/asn1/x_algor.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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); -- 2.47.2