From 02121df47d694a2e450076e02089dda2fcde3f3b Mon Sep 17 00:00:00 2001 From: Neil Horman Date: Mon, 17 Feb 2025 09:24:26 -0500 Subject: [PATCH] Fix memory leak in ecdsa_keygen_knownanswer_test MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit We allocate an EC_POINT with EC_POINT_new here, but in failing a subsequent check, we don't free it, correct that. Fixes #26779 Reviewed-by: Saša Nedvědický Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/26799) (cherry picked from commit 20a2f3beba9be6e226a0633b60c29e8a928ccd21) --- crypto/ec/ec_key.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crypto/ec/ec_key.c b/crypto/ec/ec_key.c index 681488e3f30..38d59da83ae 100644 --- a/crypto/ec/ec_key.c +++ b/crypto/ec/ec_key.c @@ -256,10 +256,7 @@ static int ecdsa_keygen_knownanswer_test(EC_KEY *eckey, BN_CTX *ctx, int len, ret = 0; OSSL_SELF_TEST *st = NULL; unsigned char bytes[512] = {0}; - EC_POINT *pub_key2 = EC_POINT_new(eckey->group); - - if (pub_key2 == NULL) - return 0; + EC_POINT *pub_key2 = NULL; st = OSSL_SELF_TEST_new(cb, cbarg); if (st == NULL) @@ -268,6 +265,9 @@ static int ecdsa_keygen_knownanswer_test(EC_KEY *eckey, BN_CTX *ctx, OSSL_SELF_TEST_onbegin(st, OSSL_SELF_TEST_TYPE_PCT_KAT, OSSL_SELF_TEST_DESC_PCT_ECDSA); + if ((pub_key2 = EC_POINT_new(eckey->group)) == NULL) + goto err; + /* pub_key = priv_key * G (where G is a point on the curve) */ if (!EC_POINT_mul(eckey->group, pub_key2, eckey->priv_key, NULL, NULL, ctx)) goto err; -- 2.47.2