From: Matt Caswell Date: Fri, 15 Oct 2021 15:23:31 +0000 (+0100) Subject: Ensure pkey_set_type handles ENGINE references correctly X-Git-Tag: OpenSSL_1_1_1m~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ce10cc8037bb8cdd1b1f383110d76f922b35808;p=thirdparty%2Fopenssl.git 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 (Merged from https://github.com/openssl/openssl/pull/16860) --- diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c index 9f1a485a5b8..7e262c573b2 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; }