diff options
author | K1 <dongbeiouba@gmail.com> | 2022-06-08 16:41:16 +0800 |
---|---|---|
committer | Todd Short <todd.short@me.com> | 2022-06-15 10:53:04 -0400 |
commit | 115eb945acd9a27bf81c6c8923f43768f9e487a8 (patch) | |
tree | 7a42d1643286c14c70bd4a244dc5a9256612abce /crypto | |
parent | 01fc9b6bce82f0534d6673659a0e59a71f57ee82 (diff) |
Fix a mem leak in evp_pkey_export_to_provider
If keymgmt is NULL, tmp_keymgmt is allocated and will not be freed.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Yang <kaishen.yy@antfin.com>
Reviewed-by: Todd Short <todd.short@me.com>
(Merged from https://github.com/openssl/openssl/pull/18499)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/evp/p_lib.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c index db1822f0d1..8d2eee11f1 100644 --- a/crypto/evp/p_lib.c +++ b/crypto/evp/p_lib.c @@ -1853,7 +1853,7 @@ void *evp_pkey_export_to_provider(EVP_PKEY *pk, OSSL_LIB_CTX *libctx, if (ctx == NULL) goto end; - tmp_keymgmt = ctx->keymgmt; + allocated_keymgmt = tmp_keymgmt = ctx->keymgmt; ctx->keymgmt = NULL; EVP_PKEY_CTX_free(ctx); } @@ -1966,8 +1966,10 @@ void *evp_pkey_export_to_provider(EVP_PKEY *pk, OSSL_LIB_CTX *libctx, if (keydata == NULL) tmp_keymgmt = NULL; - if (keymgmt != NULL) + if (keymgmt != NULL && tmp_keymgmt != NULL) { *keymgmt = tmp_keymgmt; + allocated_keymgmt = NULL; + } EVP_KEYMGMT_free(allocated_keymgmt); return keydata; |