]> 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)
committerNeil Horman <nhorman@openssl.org>
Sat, 14 Jun 2025 11:59:12 +0000 (07:59 -0400)
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>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27813)

providers/implementations/keymgmt/ecx_kmgmt.c
providers/implementations/keymgmt/mac_legacy_kmgmt.c

index f2e7c795fc11dc17d9f6d2820e14fb948cea9ea3..e5f95669ea56cc00abd97099bf950e12be7510f5 100644 (file)
@@ -845,6 +845,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);