diff options
author | Paul Yang <yang.yang@baishancloud.com> | 2018-09-05 22:01:33 +0800 |
---|---|---|
committer | Paul Yang <yang.yang@baishancloud.com> | 2018-09-07 18:12:26 +0800 |
commit | 81c7945388a49799f819f5ca5bfe6acd506840c3 (patch) | |
tree | 2bb098b9d8fcaffc3cf96cdab28039bae7b03bd5 /crypto/evp | |
parent | 571286b0a463b02ef2f9040a7e5d602635854832 (diff) |
Allow EVP_MD_CTX_set_pkey_ctx to accept NULL pctx
Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/7113)
Diffstat (limited to 'crypto/evp')
-rw-r--r-- | crypto/evp/evp_lib.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/crypto/evp/evp_lib.c b/crypto/evp/evp_lib.c index 81a5bf0012..1b3c9840c6 100644 --- a/crypto/evp/evp_lib.c +++ b/crypto/evp/evp_lib.c @@ -462,9 +462,21 @@ EVP_PKEY_CTX *EVP_MD_CTX_pkey_ctx(const EVP_MD_CTX *ctx) void EVP_MD_CTX_set_pkey_ctx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx) { + /* + * it's reasonable to set NULL pctx (a.k.a clear the ctx->pctx), so + * we have to deal with the cleanup job here. + */ + if (!EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX)) + EVP_PKEY_CTX_free(ctx->pctx); + ctx->pctx = pctx; - /* make sure pctx is not freed when destroying EVP_MD_CTX */ - EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX); + + if (pctx != NULL) { + /* make sure pctx is not freed when destroying EVP_MD_CTX */ + EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX); + } else { + EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX); + } } void *EVP_MD_CTX_md_data(const EVP_MD_CTX *ctx) |