summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPauli <ppzgs1@gmail.com>2021-02-08 10:54:52 +1000
committerPauli <ppzgs1@gmail.com>2021-02-12 12:28:55 +1000
commit31f7ff37b403f5ed50cf2e1e828a2e63576dac58 (patch)
tree8f95162af10577121a5d58db64827c03c6909880
parent22040fb790c854cefb04bed98ed38ea6357daf83 (diff)
EVP: fix reference counting for digest operations.
The reference count wasn't being incremented but the EVP_MD pointer was being held. In a no cache build, this resulted in a failure on update in some circumstances. Reviewed-by: Shane Lontis <shane.lontis@oracle.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/14126)
-rw-r--r--crypto/evp/digest.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c
index 40aedae47b..3dfcfcda8e 100644
--- a/crypto/evp/digest.c
+++ b/crypto/evp/digest.c
@@ -235,8 +235,10 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
#else
EVP_MD *provmd = EVP_MD_fetch(NULL, OBJ_nid2sn(type->type), "");
- if (provmd == NULL)
+ if (provmd == NULL) {
+ ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
return 0;
+ }
type = provmd;
EVP_MD_free(ctx->fetched_digest);
ctx->fetched_digest = provmd;
@@ -248,6 +250,14 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
ctx->digest->freectx(ctx->provctx);
ctx->provctx = NULL;
}
+ if (type->prov != NULL && ctx->fetched_digest != type) {
+ if (!EVP_MD_up_ref((EVP_MD *)type)) {
+ ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
+ return 0;
+ }
+ EVP_MD_free(ctx->fetched_digest);
+ ctx->fetched_digest = (EVP_MD *)type;
+ }
ctx->digest = type;
if (ctx->provctx == NULL) {
ctx->provctx = ctx->digest->newctx(ossl_provider_ctx(type->prov));