]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Clear md_data only when necessary
authorMatt Caswell <matt@openssl.org>
Tue, 11 Jan 2022 17:13:39 +0000 (17:13 +0000)
committerMatt Caswell <matt@openssl.org>
Thu, 13 Jan 2022 11:50:40 +0000 (11:50 +0000)
PR #17255 fixed a bug in EVP_DigestInit_ex(). While backporting the PR
to 1.1.1 (see #17472) I spotted an error in the original patch. This fixes
it.

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

crypto/evp/digest.c

index cdcb60092ea2c03135a33a4c67d2222a3b06300c..d4685e64890600e80e9822aef988d5e757629ca3 100644 (file)
@@ -33,9 +33,10 @@ static void cleanup_old_md_data(EVP_MD_CTX *ctx, int force)
             ctx->digest->cleanup(ctx);
         if (ctx->md_data != NULL && ctx->digest->ctx_size > 0
                 && (!EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)
-                    || force))
+                    || force)) {
             OPENSSL_clear_free(ctx->md_data, ctx->digest->ctx_size);
-        ctx->md_data = NULL;
+            ctx->md_data = NULL;
+        }
     }
 }