summaryrefslogtreecommitdiffstats
path: root/crypto/core_fetch.c
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2022-04-20 18:34:09 +0200
committerRichard Levitte <levitte@openssl.org>2022-05-05 15:14:37 +0200
commit27c4ac706a059aab81f3d1d8cc0ba0b3693bf155 (patch)
tree31175a2df60535a0bdd854f8c20a464791afc9eb /crypto/core_fetch.c
parent749691374ccf87418ca0e6664a9b9c831dcfe108 (diff)
Refactor method construction pre- and post-condition
The existing pre- and post-condition functions are supposed to check if methods have already been created and stored, using provider operation bits. This is supposed to only be done for "permanent" method stores. However, the way the pre-condition was called, it could not know if the set of implementations to be stored is likely to end up in a "permanent" or a temporary store. It needs access to the |no_store| flag returned by the provider's operation query function, because that call was done after the pre-condition was called. This requires a bit of refactoring, primarly of |algorithm_do_this()|, but also of |ossl_method_construct_precondition()|. Fixes #18150 Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/18151) (cherry picked from commit 10937d5867039afbf869c8514245ed7599b61307)
Diffstat (limited to 'crypto/core_fetch.c')
-rw-r--r--crypto/core_fetch.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/crypto/core_fetch.c b/crypto/core_fetch.c
index 367f6ba8a4..6b25379f7b 100644
--- a/crypto/core_fetch.c
+++ b/crypto/core_fetch.c
@@ -24,16 +24,28 @@ struct construct_data_st {
void *mcm_data;
};
+static int is_temporary_method_store(int no_store, void *cbdata)
+{
+ struct construct_data_st *data = cbdata;
+
+ return no_store && !data->force_store;
+}
+
static int ossl_method_construct_precondition(OSSL_PROVIDER *provider,
- int operation_id, void *cbdata,
- int *result)
+ int operation_id, int no_store,
+ void *cbdata, int *result)
{
if (!ossl_assert(result != NULL)) {
ERR_raise(ERR_LIB_CRYPTO, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
- if (!ossl_provider_test_operation_bit(provider, operation_id, result))
+ /* Assume that no bits are set */
+ *result = 0;
+
+ /* No flag bits for temporary stores */
+ if (!is_temporary_method_store(no_store, cbdata)
+ && !ossl_provider_test_operation_bit(provider, operation_id, result))
return 0;
/*
@@ -56,7 +68,9 @@ static int ossl_method_construct_postcondition(OSSL_PROVIDER *provider,
}
*result = 1;
- return no_store != 0
+
+ /* No flag bits for temporary stores */
+ return is_temporary_method_store(no_store, cbdata)
|| ossl_provider_set_operation_bit(provider, operation_id);
}
@@ -82,7 +96,7 @@ static void ossl_method_construct_this(OSSL_PROVIDER *provider,
* of the passed method.
*/
- if (data->force_store || !no_store) {
+ if (!is_temporary_method_store(no_store, data)) {
/* If we haven't been told not to store, add to the global store */
data->mcm->put(NULL, method, provider, algo->algorithm_names,
algo->property_definition, data->mcm_data);