From 6d9ce13b620939fcf2647418669013ff79fd27a4 Mon Sep 17 00:00:00 2001 From: Frederik Wedel-Heinen Date: Sat, 21 Dec 2024 15:32:32 +0100 Subject: [PATCH] Fixes some memory leaks when errors occur in ossl_cmp_rp_new(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Dmitry Belyavskiy Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/26235) Signed-off-by: 王静 --- crypto/cmp/cmp_msg.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/crypto/cmp/cmp_msg.c b/crypto/cmp/cmp_msg.c index c8e467f3c2..c4cf46229c 100644 --- a/crypto/cmp/cmp_msg.c +++ b/crypto/cmp/cmp_msg.c @@ -584,23 +584,20 @@ OSSL_CMP_MSG *ossl_cmp_rp_new(OSSL_CMP_CTX *ctx, const OSSL_CMP_PKISI *si, goto err; rep = msg->body->value.rp; - if ((si1 = OSSL_CMP_PKISI_dup(si)) == NULL) + if ((si1 = OSSL_CMP_PKISI_dup(si)) == NULL + || !sk_OSSL_CMP_PKISI_push(rep->status, si1)) goto err; - if (!sk_OSSL_CMP_PKISI_push(rep->status, si1)) { - OSSL_CMP_PKISI_free(si1); - goto err; - } + si1 = NULL; /* ownership transferred to rep->status */ if ((rep->revCerts = sk_OSSL_CRMF_CERTID_new_null()) == NULL) goto err; if (cid != NULL) { - if ((cid_copy = OSSL_CRMF_CERTID_dup(cid)) == NULL) - goto err; - if (!sk_OSSL_CRMF_CERTID_push(rep->revCerts, cid_copy)) { - OSSL_CRMF_CERTID_free(cid_copy); + if ((cid_copy = OSSL_CRMF_CERTID_dup(cid)) == NULL + || !sk_OSSL_CRMF_CERTID_push(rep->revCerts, cid_copy)) goto err; - } + + cid_copy = NULL; /* ownership transferred to rep->revCerts */ } if (!unprotectedErrors @@ -612,6 +609,8 @@ OSSL_CMP_MSG *ossl_cmp_rp_new(OSSL_CMP_CTX *ctx, const OSSL_CMP_PKISI *si, err: ERR_raise(ERR_LIB_CMP, CMP_R_ERROR_CREATING_RP); + OSSL_CMP_PKISI_free(si1); + OSSL_CRMF_CERTID_free(cid_copy); OSSL_CMP_MSG_free(msg); return NULL; } -- Gitee