summaryrefslogtreecommitdiffstats
path: root/crypto/property/property.c
diff options
context:
space:
mode:
authorPauli <pauli@openssl.org>2021-03-30 02:29:01 +0200
committerPauli <pauli@openssl.org>2021-04-08 09:46:35 +0200
commit860ecfd70022fa5700c7fb129845129b4c674ecd (patch)
tree1ade8cb44f104dcd2a7d8b8b03d7bf2b65d9fdea /crypto/property/property.c
parentapps: fix AES CBC performance loop (diff)
downloadopenssl-860ecfd70022fa5700c7fb129845129b4c674ecd.tar.xz
openssl-860ecfd70022fa5700c7fb129845129b4c674ecd.zip
property: check return values from the property locking calls.
A failure to obtain a lock would have resulted in much badness, now it results in a failure return. Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/14773)
Diffstat (limited to 'crypto/property/property.c')
-rw-r--r--crypto/property/property.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/crypto/property/property.c b/crypto/property/property.c
index b6e295e5cd..c424e37bfb 100644
--- a/crypto/property/property.c
+++ b/crypto/property/property.c
@@ -117,17 +117,17 @@ static void ossl_method_free(METHOD *method)
(*method->free)(method->method);
}
-int ossl_property_read_lock(OSSL_METHOD_STORE *p)
+static __owur int ossl_property_read_lock(OSSL_METHOD_STORE *p)
{
return p != NULL ? CRYPTO_THREAD_read_lock(p->lock) : 0;
}
-int ossl_property_write_lock(OSSL_METHOD_STORE *p)
+static __owur int ossl_property_write_lock(OSSL_METHOD_STORE *p)
{
return p != NULL ? CRYPTO_THREAD_write_lock(p->lock) : 0;
}
-int ossl_property_unlock(OSSL_METHOD_STORE *p)
+static int ossl_property_unlock(OSSL_METHOD_STORE *p)
{
return p != 0 ? CRYPTO_THREAD_unlock(p->lock) : 0;
}
@@ -246,7 +246,10 @@ int ossl_method_store_add(OSSL_METHOD_STORE *store, const OSSL_PROVIDER *prov,
* A write lock is used unconditionally because we wend our way down to the
* property string code which isn't locking friendly.
*/
- ossl_property_write_lock(store);
+ if (!ossl_property_write_lock(store)) {
+ OPENSSL_free(impl);
+ return 0;
+ }
ossl_method_cache_flush(store, nid);
if ((impl->properties = ossl_prop_defn_get(store->ctx, properties)) == NULL) {
impl->properties = ossl_parse_property(store->ctx, properties);
@@ -298,7 +301,8 @@ int ossl_method_store_remove(OSSL_METHOD_STORE *store, int nid,
if (nid <= 0 || method == NULL || store == NULL)
return 0;
- ossl_property_write_lock(store);
+ if (!ossl_property_write_lock(store))
+ return 0;
ossl_method_cache_flush(store, nid);
alg = ossl_method_store_retrieve(store, nid);
if (alg == NULL) {
@@ -349,7 +353,8 @@ int ossl_method_store_fetch(OSSL_METHOD_STORE *store, int nid,
* This only needs to be a read lock, because queries never create property
* names or value and thus don't modify any of the property string layer.
*/
- ossl_property_read_lock(store);
+ if (!ossl_property_read_lock(store))
+ return 0;
alg = ossl_method_store_retrieve(store, nid);
if (alg == NULL) {
ossl_property_unlock(store);
@@ -425,14 +430,16 @@ static void ossl_method_cache_flush(OSSL_METHOD_STORE *store, int nid)
}
}
-void ossl_method_store_flush_cache(OSSL_METHOD_STORE *store, int all)
+int ossl_method_store_flush_cache(OSSL_METHOD_STORE *store, int all)
{
void *arg = (all != 0 ? store->algs : NULL);
- ossl_property_write_lock(store);
+ if (!ossl_property_write_lock(store))
+ return 0;
ossl_sa_ALGORITHM_doall_arg(store->algs, &impl_cache_flush_alg, arg);
store->nelem = 0;
ossl_property_unlock(store);
+ return 1;
}
IMPLEMENT_LHASH_DOALL_ARG(QUERY, IMPL_CACHE_FLUSH);
@@ -508,7 +515,8 @@ int ossl_method_store_cache_get(OSSL_METHOD_STORE *store, int nid,
if (nid <= 0 || store == NULL)
return 0;
- ossl_property_read_lock(store);
+ if (!ossl_property_read_lock(store))
+ return 0;
alg = ossl_method_store_retrieve(store, nid);
if (alg == NULL)
goto err;
@@ -541,7 +549,8 @@ int ossl_method_store_cache_set(OSSL_METHOD_STORE *store, int nid,
if (prop_query == NULL)
return 1;
- ossl_property_write_lock(store);
+ if (!ossl_property_write_lock(store))
+ return 0;
if (store->need_flush)
ossl_method_cache_flush_some(store);
alg = ossl_method_store_retrieve(store, nid);