]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix memory leak in ecdsa_keygen_knownanswer_test
authorNeil Horman <nhorman@openssl.org>
Mon, 17 Feb 2025 14:24:26 +0000 (09:24 -0500)
committerNeil Horman <nhorman@openssl.org>
Wed, 19 Feb 2025 14:40:03 +0000 (09:40 -0500)
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)

(cherry picked from commit 20a2f3beba9be6e226a0633b60c29e8a928ccd21)

crypto/ec/ec_key.c

index 901630dad5e7a04692d12b29a28c235602169686..a4e0fc80d88734421e30007cad0e7ddeda11f45c 100644 (file)
@@ -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;