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ý <sashan@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/26799)
This commit is contained in:
Neil Horman 2025-02-17 09:24:26 -05:00
parent 5a1819a150
commit 20a2f3beba

View file

@ -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;