]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix memory leak in error path of ec_gen_init()
authorNiels Dossche <niels.dossche@ugent.be>
Mon, 8 Dec 2025 14:17:56 +0000 (15:17 +0100)
committerTomas Mraz <tomas@openssl.org>
Thu, 11 Dec 2025 12:13:35 +0000 (13:13 +0100)
ec_gen_set_params() can fail after some big numbers have already been
copied over. Those need to be cleaned to avoid a memory leak on failure.
This can be done with ec_gen_cleanup(), which is also consistent in how
the ecx_gen code does it.

Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/29335)

providers/implementations/keymgmt/ec_kmgmt.c

index 7e9b7236225b3323b1913439eb41a298e0898f3b..cc3cf75cd8082f02ae8d0912a2df94417bd85281 100644 (file)
@@ -985,7 +985,7 @@ static void *ec_gen_init(void *provctx, int selection,
         gctx->ecdh_mode = 0;
         OSSL_FIPS_IND_INIT(gctx)
         if (!ec_gen_set_params(gctx, params)) {
-            OPENSSL_free(gctx);
+            ec_gen_cleanup(gctx);
             gctx = NULL;
         }
     }