Plug a leak of cont in CMS_dataInit()
authortb <tb@openbsd.org>
Tue, 22 Aug 2023 08:44:15 +0000 (08:44 +0000)
committertb <tb@openbsd.org>
Tue, 22 Aug 2023 08:44:15 +0000 (08:44 +0000)
This and ts/ts_rsp_sign.c r1.32 were part of OpenSSL 309e73df.

ok jsing

lib/libcrypto/cms/cms_lib.c

index 37a11ba..9f8e13d 100644 (file)
@@ -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;