diff options
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/evp/keymgmt_lib.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/crypto/evp/keymgmt_lib.c b/crypto/evp/keymgmt_lib.c index f3118a76c9..301e1a8a2f 100644 --- a/crypto/evp/keymgmt_lib.c +++ b/crypto/evp/keymgmt_lib.c @@ -31,12 +31,15 @@ static int match_type(const EVP_KEYMGMT *keymgmt1, const EVP_KEYMGMT *keymgmt2) int evp_keymgmt_util_try_import(const OSSL_PARAM params[], void *arg) { struct evp_keymgmt_util_try_import_data_st *data = arg; + int delete_on_error = 0; /* Just in time creation of keydata */ - if (data->keydata == NULL - && (data->keydata = evp_keymgmt_newdata(data->keymgmt)) == NULL) { - ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); - return 0; + if (data->keydata == NULL) { + if ((data->keydata = evp_keymgmt_newdata(data->keymgmt)) == NULL) { + ERR_raise(ERR_LIB_EVP, ERR_R_MALLOC_FAILURE); + return 0; + } + delete_on_error = 1; } /* @@ -46,8 +49,14 @@ int evp_keymgmt_util_try_import(const OSSL_PARAM params[], void *arg) if (params[0].key == NULL) return 1; - return evp_keymgmt_import(data->keymgmt, data->keydata, data->selection, - params); + if (evp_keymgmt_import(data->keymgmt, data->keydata, data->selection, + params)) + return 1; + if (delete_on_error) { + evp_keymgmt_freedata(data->keymgmt, data->keydata); + data->keydata = NULL; + } + return 0; } int evp_keymgmt_util_assign_pkey(EVP_PKEY *pkey, EVP_KEYMGMT *keymgmt, @@ -149,11 +158,9 @@ void *evp_keymgmt_util_export_to_provider(EVP_PKEY *pk, EVP_KEYMGMT *keymgmt) * which does the import for us. If successful, we're done. */ if (!evp_keymgmt_util_export(pk, OSSL_KEYMGMT_SELECT_ALL, - &evp_keymgmt_util_try_import, &import_data)) { + &evp_keymgmt_util_try_import, &import_data)) /* If there was an error, bail out */ - evp_keymgmt_freedata(keymgmt, import_data.keydata); return NULL; - } if (!CRYPTO_THREAD_write_lock(pk->lock)) { evp_keymgmt_freedata(keymgmt, import_data.keydata); |