]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Allow our *_gen_cleanup functions to tolerate a NULL ctx
authorMatt Caswell <matt@openssl.org>
Wed, 11 Jun 2025 08:50:16 +0000 (09:50 +0100)
committerMatt Caswell <matt@openssl.org>
Thu, 12 Jun 2025 11:02:12 +0000 (12:02 +0100)
Our *_gen_cleanup functions are essentially "free" functions. Our
free functions tolerate NULL being passed. We are being inconsistent with
our *_gen_cleanup functions. Some of them tolerate NULL and others do not.

We should consistently tolerate NULL.

See also #27795

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/27807)

(cherry picked from commit fcc5df53697a63d0f153b0086054f509aad8e6bb)

providers/implementations/keymgmt/ecx_kmgmt.c
providers/implementations/keymgmt/mac_legacy_kmgmt.c
providers/implementations/keymgmt/ml_dsa_kmgmt.c
providers/implementations/keymgmt/ml_kem_kmgmt.c
providers/implementations/keymgmt/slh_dsa_kmgmt.c
providers/implementations/keymgmt/template_kmgmt.c

index 230a75cc5795c890bace012abd09645db0484eab..6ea0001e5787f73382668af83cbb27e636a373b2 100644 (file)
@@ -843,6 +843,9 @@ static void ecx_gen_cleanup(void *genctx)
 {
     struct ecx_gen_ctx *gctx = genctx;
 
+    if (gctx == NULL)
+        return;
+
     OPENSSL_clear_free(gctx->dhkem_ikm, gctx->dhkem_ikmlen);
     OPENSSL_free(gctx->propq);
     OPENSSL_free(gctx);
index 161a433caf5a1eee3e45c6a4e128e9989203d905..a83017e3aebf287597bb16456195e71e24823a66 100644 (file)
@@ -519,6 +519,9 @@ static void mac_gen_cleanup(void *genctx)
 {
     struct mac_gen_ctx *gctx = genctx;
 
+    if (gctx == NULL)
+        return;
+
     OPENSSL_secure_clear_free(gctx->priv_key, gctx->priv_key_len);
     ossl_prov_cipher_reset(&gctx->cipher);
     OPENSSL_free(gctx);
index a31a308c9c79f935b33c0c41ed2cae530a58dd72..53feeba4ac3dd761ec46dc5e511b76f39eb97d08 100644 (file)
@@ -529,6 +529,9 @@ static void ml_dsa_gen_cleanup(void *genctx)
 {
     struct ml_dsa_gen_ctx *gctx = genctx;
 
+    if (gctx == NULL)
+        return;
+
     OPENSSL_cleanse(gctx->entropy, gctx->entropy_len);
     OPENSSL_free(gctx->propq);
     OPENSSL_free(gctx);
index ba854c66378482ebd4ff193f2ce6be3b941ba9c8..3936b6c3cd40000bd17e33563ecd97cfaffe264a 100644 (file)
@@ -794,6 +794,9 @@ static void ml_kem_gen_cleanup(void *vgctx)
 {
     PROV_ML_KEM_GEN_CTX *gctx = vgctx;
 
+    if (gctx == NULL)
+        return;
+
     if (gctx->seed != NULL)
         OPENSSL_cleanse(gctx->seed, ML_KEM_RANDOM_BYTES);
     OPENSSL_free(gctx->propq);
index d3803424a6a176167466fa63d8f7fe15fc6b1bd2..cd2ebea72abbfcbd2d8fe472f1779f7d4015452f 100644 (file)
@@ -406,6 +406,9 @@ static void slh_dsa_gen_cleanup(void *genctx)
 {
     struct slh_dsa_gen_ctx *gctx = genctx;
 
+    if (gctx == NULL)
+        return;
+
     OPENSSL_cleanse(gctx->entropy, gctx->entropy_len);
     OPENSSL_free(gctx->propq);
     OPENSSL_free(gctx);
index b8e377a7f91247b319a3a3db2d4ccfd0bd5dae32..c54ad7837e5c45c8bf1b546800dec9cd11934e82 100644 (file)
@@ -387,6 +387,9 @@ static void template_gen_cleanup(void *genctx)
 {
     struct template_gen_ctx *gctx = genctx;
 
+    if (gctx == NULL)
+        return;
+
     debug_print("gen cleanup for %p\n", gctx);
     OPENSSL_free(gctx);
 }