diff options
author | Matt Caswell <matt@openssl.org> | 2021-10-15 16:23:31 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2021-10-21 17:08:24 +0100 |
commit | 3ce10cc8037bb8cdd1b1f383110d76f922b35808 (patch) | |
tree | a7f18465facff640ddbfc51fb44c17a1528b199a | |
parent | 2f8b8045e6b9a7780873c28c569a8a6388e11306 (diff) |
Ensure pkey_set_type handles ENGINE references correctly
pkey_set_type should not consume the ENGINE references that may be
passed to it.
Fixes #16757
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/16860)
-rw-r--r-- | crypto/evp/p_lib.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c index 9f1a485a5b..7e262c573b 100644 --- a/crypto/evp/p_lib.c +++ b/crypto/evp/p_lib.c @@ -212,10 +212,15 @@ static int pkey_set_type(EVP_PKEY *pkey, ENGINE *e, int type, const char *str, } if (pkey) { pkey->ameth = ameth; - pkey->engine = e; - pkey->type = pkey->ameth->pkey_id; pkey->save_type = type; +# ifndef OPENSSL_NO_ENGINE + if (eptr == NULL && e != NULL && !ENGINE_init(e)) { + EVPerr(EVP_F_PKEY_SET_TYPE, EVP_R_INITIALIZATION_ERROR); + return 0; + } +# endif + pkey->engine = e; } return 1; } |