From: Tomas Mraz Date: Fri, 13 Nov 2020 14:57:27 +0000 (+0100) Subject: Fix regression in EVP_DigestInit_ex: crash when called with NULL type X-Git-Tag: openssl-3.0.0-alpha10~256 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5de9863bf33e6103264507b8ff87cd58b9c97a52;p=thirdparty%2Fopenssl.git Fix regression in EVP_DigestInit_ex: crash when called with NULL type Reviewed-by: Dmitry Belyavskiy Reviewed-by: Shane Lontis (Merged from https://github.com/openssl/openssl/pull/13402) --- diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c index 19d9face898..b0ce61f935c 100644 --- a/crypto/evp/digest.c +++ b/crypto/evp/digest.c @@ -170,8 +170,15 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) ctx->provctx = NULL; } - if (type != NULL) + if (type != NULL) { ctx->reqdigest = type; + } else { + if (ctx->digest == NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_NO_DIGEST_SET); + return 0; + } + type = ctx->digest; + } /* TODO(3.0): Legacy work around code below. Remove this */ #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) @@ -292,12 +299,6 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) ctx->engine = impl; } else ctx->engine = NULL; - } else { - if (!ctx->digest) { - ERR_raise(ERR_LIB_EVP, EVP_R_NO_DIGEST_SET); - return 0; - } - type = ctx->digest; } #endif if (ctx->digest != type) {