]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix potential memory leak on failure of dsa_gen_init()
authorNiels Dossche <niels.dossche@ugent.be>
Wed, 20 Nov 2024 19:22:43 +0000 (20:22 +0100)
committerTomas Mraz <tomas@openssl.org>
Mon, 25 Nov 2024 14:11:08 +0000 (15:11 +0100)
When dsa_gen_set_params()  returns 0, it could have duplicated the memory for the parameter
OSSL_PKEY_PARAM_FFC_DIGEST already in gctx->mdname, leading to a memory leak.

Allocated here: https://github.com/openssl/openssl/blob/47a80fd2034cd4314d3b4958539dcd3106087109/providers/implementations/keymgmt/dsa_kmgmt.c#L524
Can return 0 here: https://github.com/openssl/openssl/blob/47a80fd2034cd4314d3b4958539dcd3106087109/providers/implementations/keymgmt/dsa_kmgmt.c#L529-L536

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/26016)

providers/implementations/keymgmt/dsa_kmgmt.c

index 3b12be27cc36733a2d45fbe46c4ef061ad5ee42c..0b41e0a173efdb1dd93b2ad1e85377ed56034962 100644 (file)
@@ -430,7 +430,7 @@ static void *dsa_gen_init(void *provctx, int selection,
         OSSL_FIPS_IND_INIT(gctx)
     }
     if (!dsa_gen_set_params(gctx, params)) {
-        OPENSSL_free(gctx);
+        dsa_gen_cleanup(gctx);
         gctx = NULL;
     }
     return gctx;