crypto: evp: fix unchecked return of ossl_provider_up_ref in keymgmt_from_algorithm

The ossl_provider_up_ref() call in keymgmt_from_algorithm() was not
checking its return value, unlike other similar calls in the codebase.
This could lead to inconsistent reference counting if the up-ref failed.

Now the return value is checked, and if the up-ref fails, the keymgmt
is freed and an error is raised, ensuring consistent cleanup.

Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
This commit is contained in:
Anton Moryakov 2025-08-27 13:58:24 +03:00
parent c66d9760a7
commit 746702ee7d
No known key found for this signature in database
GPG Key ID: 6E5D136E90D8701D
1 changed files with 5 additions and 2 deletions

View File

@ -261,8 +261,11 @@ static void *keymgmt_from_algorithm(int name_id,
return NULL;
}
keymgmt->prov = prov;
if (prov != NULL)
ossl_provider_up_ref(prov);
if (prov != NULL && !ossl_provider_up_ref(prov)) {
EVP_KEYMGMT_free(keymgmt);
ERR_raise(ERR_LIB_EVP, EVP_R_INITIALIZATION_ERROR);
return NULL;
}
#ifndef FIPS_MODULE
keymgmt->legacy_alg = get_legacy_alg_type_from_keymgmt(keymgmt);