]> 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:54 +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 e4f6ce34f7f270c80094e51623b25ea39b16e0da..305dc3a6b831d3c2c52b3ebd178873dbcd241439 100644 (file)
@@ -981,7 +981,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;
         }
     }