diff options
author | Tomas Mraz <tmraz@fedoraproject.org> | 2020-11-13 15:57:27 +0100 |
---|---|---|
committer | Tomas Mraz <tmraz@fedoraproject.org> | 2020-11-26 17:39:26 +0100 |
commit | 5de9863bf33e6103264507b8ff87cd58b9c97a52 (patch) | |
tree | 9fafe4fc53bfa53b1d954e015e9dd219a80a6e96 /crypto | |
parent | 8d8dd09b969dd22112137634125e1634bb8e5c4c (diff) | |
download | openssl-5de9863bf33e6103264507b8ff87cd58b9c97a52.tar.gz |
Fix regression in EVP_DigestInit_ex: crash when called with NULL type
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/13402)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/evp/digest.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c index 19d9face89..b0ce61f935 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) { |