]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
crypto/x509/v3_lib.c: Free tmpext if X509V3_EXT_add() fails to avoid memory leak
authorJiashengJiang <jiasheng@purdue.edu>
Mon, 5 May 2025 17:46:53 +0000 (13:46 -0400)
committerTomas Mraz <tomas@openssl.org>
Mon, 19 May 2025 14:19:19 +0000 (16:19 +0200)
Add OPENSSL_free to free tmpext if X509V3_EXT_add() fails to avoid memory leak.

Fixes: 878dc8dd95 ("Join the x509 and x509v3 directories")
Signed-off-by: JiashengJiang <jiasheng@purdue.edu>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27566)

(cherry picked from commit 5f661e4e96bc3bfa52b4e0735f407cb41f162869)

crypto/x509/v3_lib.c

index 5ffeb75d9f5b2af83abb21415507067dc8684bc9..f0b82bb220083411803dd09d02e0a9b5f177adf6 100644 (file)
@@ -99,7 +99,11 @@ int X509V3_EXT_add_alias(int nid_to, int nid_from)
     *tmpext = *ext;
     tmpext->ext_nid = nid_to;
     tmpext->ext_flags |= X509V3_EXT_DYNAMIC;
-    return X509V3_EXT_add(tmpext);
+    if (!X509V3_EXT_add(tmpext)) {
+        OPENSSL_free(tmpext);
+        return 0;
+    }
+    return 1;
 }
 
 void X509V3_EXT_cleanup(void)