summaryrefslogtreecommitdiffstats
path: root/crypto/property
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2022-06-06 10:06:57 +0100
committerMatt Caswell <matt@openssl.org>2022-06-09 11:37:48 +0100
commit6c98a46c4742d40870db83142309c94b66d41e25 (patch)
tree4ab32bcf01db65982bfa163a18142f09da6c9ee9 /crypto/property
parent17703a0e65618795d01c67ddaf0bd28b08dd3955 (diff)
Assert that a property definition cache entry is the first
When adding a property definition cache entry for a given property query string we add an assert that we are not replacing an existing entry. If we are then that indicates a bug in the caller. Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Todd Short <todd.short@me.com> Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/18458) (cherry picked from commit 5f4b3db624a83b812f23412e698ffd9c4284f87a)
Diffstat (limited to 'crypto/property')
-rw-r--r--crypto/property/defn_cache.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/crypto/property/defn_cache.c b/crypto/property/defn_cache.c
index 8007599526..920dbdc096 100644
--- a/crypto/property/defn_cache.c
+++ b/crypto/property/defn_cache.c
@@ -85,6 +85,11 @@ OSSL_PROPERTY_LIST *ossl_prop_defn_get(OSSL_LIB_CTX *ctx, const char *prop)
return r != NULL ? r->defn : NULL;
}
+/*
+ * Cache the property list for a given property string. Callers of this function
+ * should call ossl_prop_defn_get first to ensure that there is no existing
+ * cache entry for this property string.
+ */
int ossl_prop_defn_set(OSSL_LIB_CTX *ctx, const char *prop,
OSSL_PROPERTY_LIST *pl)
{
@@ -116,8 +121,14 @@ int ossl_prop_defn_set(OSSL_LIB_CTX *ctx, const char *prop,
p->defn = pl;
memcpy(p->body, prop, len + 1);
old = lh_PROPERTY_DEFN_ELEM_insert(property_defns, p);
- if (old != NULL) {
- property_defn_free(old);
+ if (!ossl_assert(old == NULL)) {
+ /*
+ * This should not happen. Any caller of ossl_prop_defn_set should
+ * have called ossl_prop_defn_get first - so we should know that
+ * there is no existing entry. If we get here we have a bug. We
+ * deliberately leak the |old| reference in order to avoid a crash
+ * if there are any existing users of it.
+ */
goto end;
}
if (!lh_PROPERTY_DEFN_ELEM_error(property_defns))