Avoid potential memory leak
authorDmitry Belyavskiy <beldmit@gmail.com>
Mon, 7 Mar 2022 16:05:57 +0000 (17:05 +0100)
committerMatt Caswell <matt@openssl.org>
Thu, 10 Mar 2022 14:10:53 +0000 (14:10 +0000)
Resolves #17827

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17828)

crypto/x509/v3_utl.c

index ae53554e58c3c3720a10f115a63a3f84df524373..688c2ee722aadf6b48bd68d7cd5702a0c3407832 100644 (file)
@@ -539,8 +539,11 @@ static int append_ia5(STACK_OF(OPENSSL_STRING) **sk,
         return 0;
 
     emtmp = OPENSSL_strndup((char *)email->data, email->length);
-    if (emtmp == NULL)
+    if (emtmp == NULL) {
+        X509_email_free(*sk);
+        *sk = NULL;
         return 0;
+    }
 
     /* Don't add duplicates */
     if (sk_OPENSSL_STRING_find(*sk, emtmp) != -1) {