Skip to content

Commit dc6d9ed

Browse files
committed
Don't try and do ossl_provider_find in ossl_provider_new
We leave it to the caller to confirm that the provider does not exist in the store. If it does exist then later adding it to the store will fail. It is possible that the provider could be added to the store in between the caller checking, and the caller calling ossl_provider_new. We leave it to the caller to properly handle the failure when it attempts to add the provider to the store. This is simpler than having ossl_provider_new try to handle it. Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#16980)
1 parent 464c2b9 commit dc6d9ed

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

crypto/provider_core.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,11 @@ static int provider_free_intern(OSSL_PROVIDER *prov, int deactivate)
505505
}
506506
#endif
507507

508+
/*
509+
* We assume that the requested provider does not already exist in the store.
510+
* The caller should check. If it does exist then adding it to the store later
511+
* will fail.
512+
*/
508513
OSSL_PROVIDER *ossl_provider_new(OSSL_LIB_CTX *libctx, const char *name,
509514
OSSL_provider_init_fn *init_function,
510515
int noconfig)
@@ -516,14 +521,6 @@ OSSL_PROVIDER *ossl_provider_new(OSSL_LIB_CTX *libctx, const char *name,
516521
if ((store = get_provider_store(libctx)) == NULL)
517522
return NULL;
518523

519-
if ((prov = ossl_provider_find(libctx, name,
520-
noconfig)) != NULL) { /* refcount +1 */
521-
ossl_provider_free(prov); /* refcount -1 */
522-
ERR_raise_data(ERR_LIB_CRYPTO, CRYPTO_R_PROVIDER_ALREADY_EXISTS,
523-
"name=%s", name);
524-
return NULL;
525-
}
526-
527524
memset(&template, 0, sizeof(template));
528525
if (init_function == NULL) {
529526
const OSSL_PROVIDER_INFO *p;

0 commit comments

Comments
 (0)