]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix memleak in ossl_ffc_params_copy if alloc fails
authorJakub Zelenka <jakub.zelenka@openssl.foundation>
Wed, 6 May 2026 16:22:47 +0000 (18:22 +0200)
committerEugene Syromiatnikov <esyr@openssl.org>
Mon, 11 May 2026 07:21:10 +0000 (09:21 +0200)
If allocation fails in ossl_ffc_params_copy, then the params that were
previously allocated are not freed. This results in a memory leak.

Fixes: dc8de3e6f1ee "Modify DSA and DH keys to use a shared FFC_PARAMS struct"
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Matt Caswell <matt@openssl.foundation>
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
MergeDate: Mon May 11 07:21:45 2026
(Merged from https://github.com/openssl/openssl/pull/31098)

crypto/ffc/ffc_params.c

index 438997931bbd7091e5367dc91782f40c5907617a..6da6527a4b0f178d2c027b40137c8c5203c953fb 100644 (file)
@@ -182,8 +182,10 @@ int ossl_ffc_params_copy(FFC_PARAMS *dst, const FFC_PARAMS *src)
     if (!ffc_bn_cpy(&dst->p, src->p)
         || !ffc_bn_cpy(&dst->g, src->g)
         || !ffc_bn_cpy(&dst->q, src->q)
-        || !ffc_bn_cpy(&dst->j, src->j))
+        || !ffc_bn_cpy(&dst->j, src->j)) {
+        ossl_ffc_params_cleanup(dst);
         return 0;
+    }
 
     dst->mdname = src->mdname;
     dst->mdprops = src->mdprops;
@@ -191,8 +193,10 @@ int ossl_ffc_params_copy(FFC_PARAMS *dst, const FFC_PARAMS *src)
     dst->seedlen = src->seedlen;
     if (src->seed != NULL) {
         dst->seed = OPENSSL_memdup(src->seed, src->seedlen);
-        if (dst->seed == NULL)
+        if (dst->seed == NULL) {
+            ossl_ffc_params_cleanup(dst);
             return 0;
+        }
     } else {
         dst->seed = NULL;
     }