From: Neil Horman Date: Mon, 17 Feb 2025 14:24:26 +0000 (-0500) Subject: Fix memory leak in ecdsa_keygen_knownanswer_test X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bdce0426495d379c29c6e4fdb272c14b9a2f4d27;p=thirdparty%2Fopenssl.git Fix memory leak in ecdsa_keygen_knownanswer_test 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) --- diff --git a/crypto/ec/ec_key.c b/crypto/ec/ec_key.c index 901630dad5e..a4e0fc80d88 100644 --- a/crypto/ec/ec_key.c +++ b/crypto/ec/ec_key.c @@ -255,10 +255,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) @@ -267,6 +264,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;