]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix a potential double free in EVP_DigestInit_ex
authorMatt Caswell <matt@openssl.org>
Mon, 14 Mar 2016 17:06:19 +0000 (17:06 +0000)
committerMatt Caswell <matt@openssl.org>
Fri, 18 Mar 2016 11:44:47 +0000 (11:44 +0000)
There is a potential double free in EVP_DigestInit_ex. This is believed
to be reached only as a result of programmer error - but we should fix it
anyway.

Issue reported by Guido Vranken.

Reviewed-by: Richard Levitte <levitte@openssl.org>
(cherry picked from commit ffe9150b1508a0ffc9e724f975691f24eb045c05)

crypto/evp/digest.c

index 2e202c8fe031a63b8292057e1cc6fb25a184063f..32167b294db12d53f216b33750e7e9a4aa32557c 100644 (file)
@@ -200,8 +200,10 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
     }
 #endif
     if (ctx->digest != type) {
-        if (ctx->digest && ctx->digest->ctx_size)
+        if (ctx->digest && ctx->digest->ctx_size) {
             OPENSSL_free(ctx->md_data);
+            ctx->md_data = NULL;
+        }
         ctx->digest = type;
         if (!(ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) && type->ctx_size) {
             ctx->update = type->update;