From: Shane Lontis Date: Wed, 2 Dec 2020 10:54:08 +0000 (+1000) Subject: Fix EVP_PKEY_CTX propq so that it uses a copy X-Git-Tag: openssl-3.0.0-alpha10~183 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ddfd7182cf2b7e69669cf4fd3471a37d09af4ea1;p=thirdparty%2Fopenssl.git Fix EVP_PKEY_CTX propq so that it uses a copy Reviewed-by: Tomas Mraz Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/12700) --- diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c index 903e30acf06..2c2d9395381 100644 --- a/crypto/evp/pmeth_lib.c +++ b/crypto/evp/pmeth_lib.c @@ -312,9 +312,14 @@ static EVP_PKEY_CTX *int_ctx_new(OSSL_LIB_CTX *libctx, EVP_KEYMGMT_free(keymgmt); return NULL; } - + if (propquery != NULL) { + ret->propquery = OPENSSL_strdup(propquery); + if (ret->propquery == NULL) { + EVP_KEYMGMT_free(keymgmt); + return NULL; + } + } ret->libctx = libctx; - ret->propquery = propquery; ret->keytype = keytype; ret->keymgmt = keymgmt; ret->legacy_keytype = id; /* TODO: Remove when #legacy key are gone */ @@ -397,6 +402,7 @@ void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx) #endif EVP_KEYMGMT_free(ctx->keymgmt); + OPENSSL_free(ctx->propquery); EVP_PKEY_free(ctx->pkey); EVP_PKEY_free(ctx->peerkey); #if !defined(OPENSSL_NO_ENGINE) && !defined(FIPS_MODULE) @@ -474,7 +480,14 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(const EVP_PKEY_CTX *pctx) rctx->operation = pctx->operation; rctx->libctx = pctx->libctx; rctx->keytype = pctx->keytype; - rctx->propquery = pctx->propquery; + rctx->propquery = NULL; + if (pctx->propquery != NULL) { + rctx->propquery = OPENSSL_strdup(pctx->propquery); + if (rctx->propquery == NULL) { + OPENSSL_free(rctx); + return NULL; + } + } if (EVP_PKEY_CTX_IS_DERIVE_OP(pctx)) { if (pctx->op.kex.exchange != NULL) { diff --git a/include/crypto/evp.h b/include/crypto/evp.h index 6eac2a0b631..c6cbd787a78 100644 --- a/include/crypto/evp.h +++ b/include/crypto/evp.h @@ -43,7 +43,7 @@ struct evp_pkey_ctx_st { * this context */ OSSL_LIB_CTX *libctx; - const char *propquery; + char *propquery; const char *keytype; EVP_KEYMGMT *keymgmt;