diff options
author | Tomas Mraz <tomas@openssl.org> | 2022-01-04 11:53:30 +0100 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2022-01-07 09:51:04 +0100 |
commit | 5b03b89f7f925384c2768874c95f1af7053fd16f (patch) | |
tree | 3585efa601cbdd5f5256c6c96f28d2b85b2a50eb /crypto | |
parent | 7b1264baab7edd82fea8b27d9ddec048bafc0048 (diff) |
EVP_PKEY_fromdata(): Do not return newly allocated pkey on failure
Fixes #17407
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17411)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/evp/pmeth_gn.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/crypto/evp/pmeth_gn.c b/crypto/evp/pmeth_gn.c index af3d990869..f9d001fdd0 100644 --- a/crypto/evp/pmeth_gn.c +++ b/crypto/evp/pmeth_gn.c @@ -365,6 +365,7 @@ int EVP_PKEY_fromdata(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey, int selection, OSSL_PARAM params[]) { void *keydata = NULL; + EVP_PKEY *allocated_pkey = NULL; if (ctx == NULL || (ctx->operation & EVP_PKEY_OP_FROMDATA) == 0) { ERR_raise(ERR_LIB_EVP, EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE); @@ -375,7 +376,7 @@ int EVP_PKEY_fromdata(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey, int selection, return -1; if (*ppkey == NULL) - *ppkey = EVP_PKEY_new(); + allocated_pkey = *ppkey = EVP_PKEY_new(); if (*ppkey == NULL) { ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); @@ -383,8 +384,13 @@ int EVP_PKEY_fromdata(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey, int selection, } keydata = evp_keymgmt_util_fromdata(*ppkey, ctx->keymgmt, selection, params); - if (keydata == NULL) + if (keydata == NULL) { + if (allocated_pkey != NULL) { + *ppkey = NULL; + EVP_PKEY_free(allocated_pkey); + } return 0; + } /* keydata is cached in *ppkey, so we need not bother with it further */ return 1; } |