]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix potential memory leak in save_statusInfo()
authorNiels Dossche <7771979+nielsdos@users.noreply.github.com>
Thu, 3 Oct 2024 14:58:30 +0000 (16:58 +0200)
committerTomas Mraz <tomas@openssl.org>
Mon, 7 Oct 2024 15:58:12 +0000 (17:58 +0200)
If sk_ASN1_UTF8STRING_push() fails then the duplicated string will leak
memory. Add a ASN1_UTF8STRING_free() to fix this.

CLA: trivial

Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/25604)

crypto/cmp/cmp_client.c

index d588bb358b725b7ab72734640d62f4621350e6a1..e8fe6f30dcb94ea1dc5c266917df0d70e26a57e8 100644 (file)
@@ -106,9 +106,12 @@ static int save_statusInfo(OSSL_CMP_CTX *ctx, OSSL_CMP_PKISI *si)
     ss = si->statusString; /* may be NULL */
     for (i = 0; i < sk_ASN1_UTF8STRING_num(ss); i++) {
         ASN1_UTF8STRING *str = sk_ASN1_UTF8STRING_value(ss, i);
+        ASN1_UTF8STRING *dup = ASN1_STRING_dup(str);
 
-        if (!sk_ASN1_UTF8STRING_push(ctx->statusString, ASN1_STRING_dup(str)))
+        if (dup == NULL || !sk_ASN1_UTF8STRING_push(ctx->statusString, dup)) {
+            ASN1_UTF8STRING_free(dup);
             return 0;
+        }
     }
     return 1;
 }