]> 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:49 +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)

(cherry picked from commit 26d138af724961c5f30263c15ae8137d4f86645b)

providers/implementations/keymgmt/ec_kmgmt.c

index fb7576ffdbf3bd391e0d4f48c2bb8fc1d14bc31d..cc55c146d38190764a77f91746f4d86cfeb79076 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;
         }
     }