From 6590b22d96e1d5eceb877e4d103bbd717c787be0 Mon Sep 17 00:00:00 2001 From: tb Date: Tue, 22 Aug 2023 08:44:15 +0000 Subject: [PATCH] Plug a leak of cont in CMS_dataInit() This and ts/ts_rsp_sign.c r1.32 were part of OpenSSL 309e73df. ok jsing --- lib/libcrypto/cms/cms_lib.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/libcrypto/cms/cms_lib.c b/lib/libcrypto/cms/cms_lib.c index 37a11ba0079..9f8e13d36fe 100644 --- a/lib/libcrypto/cms/cms_lib.c +++ b/lib/libcrypto/cms/cms_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cms_lib.c,v 1.19 2023/07/28 10:28:02 tb Exp $ */ +/* $OpenBSD: cms_lib.c,v 1.20 2023/08/22 08:44:15 tb Exp $ */ /* * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project. @@ -144,15 +144,13 @@ cms_content_bio(CMS_ContentInfo *cms) BIO * CMS_dataInit(CMS_ContentInfo *cms, BIO *icont) { - BIO *cmsbio, *cont; + BIO *cmsbio = NULL, *cont = NULL; - if (icont) - cont = icont; - else + if ((cont = icont) == NULL) cont = cms_content_bio(cms); - if (!cont) { + if (cont == NULL) { CMSerror(CMS_R_NO_CONTENT); - return NULL; + goto err; } switch (OBJ_obj2nid(cms->contentType)) { @@ -177,13 +175,16 @@ CMS_dataInit(CMS_ContentInfo *cms, BIO *icont) default: CMSerror(CMS_R_UNSUPPORTED_TYPE); - return NULL; + goto err; } - if (cmsbio) - return BIO_push(cmsbio, cont); + if (cmsbio == NULL) + goto err; + + return BIO_push(cmsbio, cont); - if (!icont) + err: + if (cont != icont) BIO_free(cont); return NULL; -- 2.20.1