Fix a possible memleak in CMS_sign_receipt
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Fri, 17 Nov 2023 06:12:42 +0000 (07:12 +0100)
committerRichard Levitte <levitte@openssl.org>
Wed, 22 Nov 2023 08:33:27 +0000 (09:33 +0100)
When an error happens after cms_encode_Receipt
the ASN1_OCTET_STRING object "os" may be leaked.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22758)

(cherry picked from commit 3e3aadd51cae1fbfb512cf4a0999d16c6a2888bd)

crypto/cms/cms_smime.c

index 479038d5732f6ba9d054661567349e6ee3b666ea..d7719267c8c83df729678afd88da361517b2baeb 100644 (file)
@@ -558,7 +558,7 @@ CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si,
 {
     CMS_SignerInfo *rct_si;
     CMS_ContentInfo *cms = NULL;
-    ASN1_OCTET_STRING **pos, *os;
+    ASN1_OCTET_STRING **pos, *os = NULL;
     BIO *rct_cont = NULL;
     int r = 0;
     const CMS_CTX *ctx = si->cms_ctx;
@@ -620,6 +620,7 @@ CMS_ContentInfo *CMS_sign_receipt(CMS_SignerInfo *si,
     if (r)
         return cms;
     CMS_ContentInfo_free(cms);
+    ASN1_OCTET_STRING_free(os);
     return NULL;
 
 }