]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix a possible memory leak in make_receipt_request
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Wed, 15 Nov 2023 18:31:28 +0000 (19:31 +0100)
committerTomas Mraz <tomas@openssl.org>
Fri, 1 Dec 2023 10:05:42 +0000 (11:05 +0100)
When the CMS_ReceiptRequest cannot be created,
the rct_to and rct_from may be leaked.

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Todd Short <todd.short@me.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22742)

apps/cms.c

index 9c4e4ee5e0553aa81ac3436d1bf6316f09f99fd2..a16318f37c106fa8f280b3a458f5a02064161799 100644 (file)
@@ -1447,6 +1447,7 @@ static CMS_ReceiptRequest
                       STACK_OF(OPENSSL_STRING) *rr_from)
 {
     STACK_OF(GENERAL_NAMES) *rct_to = NULL, *rct_from = NULL;
+    CMS_ReceiptRequest *rr;
 
     rct_to = make_names_stack(rr_to);
     if (rct_to == NULL)
@@ -1458,10 +1459,14 @@ static CMS_ReceiptRequest
     } else {
         rct_from = NULL;
     }
-    return CMS_ReceiptRequest_create0_ex(NULL, -1, rr_allorfirst, rct_from,
-                                         rct_to, app_get0_libctx());
+    rr = CMS_ReceiptRequest_create0_ex(NULL, -1, rr_allorfirst, rct_from,
+                                       rct_to, app_get0_libctx());
+    if (rr == NULL)
+        goto err;
+    return rr;
  err:
     sk_GENERAL_NAMES_pop_free(rct_to, GENERAL_NAMES_free);
+    sk_GENERAL_NAMES_pop_free(rct_from, GENERAL_NAMES_free);
     return NULL;
 }