Ensure we call the cleanup() function when cleaning an EVP_CIPHER_CTX
authorMatt Caswell <matt@openssl.org>
Thu, 29 Sep 2022 11:08:49 +0000 (12:08 +0100)
committerMatt Caswell <matt@openssl.org>
Mon, 3 Oct 2022 14:01:12 +0000 (15:01 +0100)
In some circumstances we were not calling the cleanup() function to
remove cipher specific data from an EVP_CIPHER_CTX.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19300)

crypto/evp/evp_enc.c

index c1f5d2ca54073d27040e58ca965c839a41ec5425..77dc815dd94201883f74355af2d8114b4580a5d3 100644 (file)
@@ -159,6 +159,8 @@ static int evp_cipher_init_internal(EVP_CIPHER_CTX *ctx,
      * (legacy code)
      */
     if (cipher != NULL && ctx->cipher != NULL) {
+        if (ctx->cipher->cleanup != NULL && !ctx->cipher->cleanup(ctx))
+            return 0;
         OPENSSL_clear_free(ctx->cipher_data, ctx->cipher->ctx_size);
         ctx->cipher_data = NULL;
     }