From 1e08f3ba9ec495fbd4a4cd6a411dc4e052626eda Mon Sep 17 00:00:00 2001 From: Pauli Date: Sat, 13 Mar 2021 10:34:49 +1000 Subject: [PATCH] property: default queries create the property values. Without this, it is necessary to query an algorithm before setting the default property query. With this, the value will be created and the default will work. Fixes #14516 Reviewed-by: Shane Lontis (Merged from https://github.com/openssl/openssl/pull/14542) --- crypto/evp/evp_fetch.c | 4 ++-- crypto/property/property.c | 2 +- crypto/property/property_parse.c | 5 +++-- include/internal/property.h | 3 ++- test/property_test.c | 31 +++++++++++++++++++++++++++---- 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/crypto/evp/evp_fetch.c b/crypto/evp/evp_fetch.c index d635db7c3e5..701abfaaf55 100644 --- a/crypto/evp/evp_fetch.c +++ b/crypto/evp/evp_fetch.c @@ -403,7 +403,7 @@ int evp_set_default_properties_int(OSSL_LIB_CTX *libctx, const char *propq, { OSSL_PROPERTY_LIST *pl = NULL; - if (propq != NULL && (pl = ossl_parse_query(libctx, propq)) == NULL) { + if (propq != NULL && (pl = ossl_parse_query(libctx, propq, 1)) == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_DEFAULT_QUERY_PARSE_ERROR); return 0; } @@ -424,7 +424,7 @@ static int evp_default_properties_merge(OSSL_LIB_CTX *libctx, const char *propq) return 1; if (plp == NULL || *plp == NULL) return EVP_set_default_properties(libctx, propq); - if ((pl1 = ossl_parse_query(libctx, propq)) == NULL) { + if ((pl1 = ossl_parse_query(libctx, propq, 1)) == NULL) { ERR_raise(ERR_LIB_EVP, EVP_R_DEFAULT_QUERY_PARSE_ERROR); return 0; } diff --git a/crypto/property/property.c b/crypto/property/property.c index 985709b2047..b6e295e5cd4 100644 --- a/crypto/property/property.c +++ b/crypto/property/property.c @@ -357,7 +357,7 @@ int ossl_method_store_fetch(OSSL_METHOD_STORE *store, int nid, } if (prop_query != NULL) - p2 = pq = ossl_parse_query(store->ctx, prop_query); + p2 = pq = ossl_parse_query(store->ctx, prop_query, 0); plp = ossl_ctx_global_properties(store->ctx, 0); if (plp != NULL && *plp != NULL) { if (pq == NULL) { diff --git a/crypto/property/property_parse.c b/crypto/property/property_parse.c index 9bc89f4d42d..b182f00d0a2 100644 --- a/crypto/property/property_parse.c +++ b/crypto/property/property_parse.c @@ -385,7 +385,8 @@ err: return res; } -OSSL_PROPERTY_LIST *ossl_parse_query(OSSL_LIB_CTX *ctx, const char *s) +OSSL_PROPERTY_LIST *ossl_parse_query(OSSL_LIB_CTX *ctx, const char *s, + int create_values) { STACK_OF(PROPERTY_DEFINITION) *sk; OSSL_PROPERTY_LIST *res = NULL; @@ -425,7 +426,7 @@ OSSL_PROPERTY_LIST *ossl_parse_query(OSSL_LIB_CTX *ctx, const char *s) prop->v.str_val = ossl_property_true; goto skip_value; } - if (!parse_value(ctx, &s, prop, 0)) + if (!parse_value(ctx, &s, prop, create_values)) prop->type = PROPERTY_TYPE_VALUE_UNDEFINED; skip_value: diff --git a/include/internal/property.h b/include/internal/property.h index 6e8b1a8259a..3d00e3cb66f 100644 --- a/include/internal/property.h +++ b/include/internal/property.h @@ -23,7 +23,8 @@ int ossl_property_parse_init(OSSL_LIB_CTX *ctx); /* Property definition parser */ OSSL_PROPERTY_LIST *ossl_parse_property(OSSL_LIB_CTX *ctx, const char *defn); /* Property query parser */ -OSSL_PROPERTY_LIST *ossl_parse_query(OSSL_LIB_CTX *ctx, const char *s); +OSSL_PROPERTY_LIST *ossl_parse_query(OSSL_LIB_CTX *ctx, const char *s, + int create_values); /* Property checker of query vs definition */ int ossl_property_match_count(const OSSL_PROPERTY_LIST *query, const OSSL_PROPERTY_LIST *defn); diff --git a/test/property_test.c b/test/property_test.c index ab61d01107c..add16ea6295 100644 --- a/test/property_test.c +++ b/test/property_test.c @@ -114,7 +114,7 @@ static int test_property_parse(int n) && add_property_names("sky", "groan", "cold", "today", "tomorrow", "n", NULL) && TEST_ptr(p = ossl_parse_property(NULL, parser_tests[n].defn)) - && TEST_ptr(q = ossl_parse_query(NULL, parser_tests[n].query)) + && TEST_ptr(q = ossl_parse_query(NULL, parser_tests[n].query, 0)) && TEST_int_eq(ossl_property_match_count(q, p), parser_tests[n].e)) r = 1; ossl_property_free(p); @@ -123,6 +123,27 @@ static int test_property_parse(int n) return r; } +static int test_property_query_value_create(void) +{ + OSSL_METHOD_STORE *store; + OSSL_PROPERTY_LIST *p = NULL, *q = NULL, *o = NULL; + int r = 0; + + if (TEST_ptr(store = ossl_method_store_new(NULL)) + && add_property_names("sky", NULL) + && TEST_ptr(p = ossl_parse_query(NULL, "sky=green", 0)) /* undefined */ + && TEST_ptr(q = ossl_parse_query(NULL, "sky=green", 1)) /* creates */ + && TEST_ptr(o = ossl_parse_query(NULL, "sky=green", 0)) /* defined */ + && TEST_int_eq(ossl_property_match_count(q, p), -1) + && TEST_int_eq(ossl_property_match_count(q, o), 1)) + r = 1; + ossl_property_free(o); + ossl_property_free(p); + ossl_property_free(q); + ossl_method_store_free(store); + return r; +} + static const struct { const char *q_global; const char *q_local; @@ -160,8 +181,9 @@ static int test_property_merge(int n) && add_property_names("colour", "urn", "clouds", "pot", "day", "night", NULL) && TEST_ptr(prop = ossl_parse_property(NULL, merge_tests[n].prop)) - && TEST_ptr(q_global = ossl_parse_query(NULL, merge_tests[n].q_global)) - && TEST_ptr(q_local = ossl_parse_query(NULL, merge_tests[n].q_local)) + && TEST_ptr(q_global = ossl_parse_query(NULL, merge_tests[n].q_global, + 0)) + && TEST_ptr(q_local = ossl_parse_query(NULL, merge_tests[n].q_local, 0)) && TEST_ptr(q_combined = ossl_property_merge(q_local, q_global)) && TEST_int_ge(ossl_property_match_count(q_combined, prop), 0)) r = 1; @@ -220,7 +242,7 @@ static int test_definition_compares(int n) r = TEST_ptr(store = ossl_method_store_new(NULL)) && add_property_names("alpha", "omega", NULL) && TEST_ptr(d = ossl_parse_property(NULL, definition_tests[n].defn)) - && TEST_ptr(q = ossl_parse_query(NULL, definition_tests[n].query)) + && TEST_ptr(q = ossl_parse_query(NULL, definition_tests[n].query, 0)) && TEST_int_eq(ossl_property_match_count(q, d), definition_tests[n].e); ossl_property_free(d); @@ -416,6 +438,7 @@ err: int setup_tests(void) { ADD_TEST(test_property_string); + ADD_TEST(test_property_query_value_create); ADD_ALL_TESTS(test_property_parse, OSSL_NELEM(parser_tests)); ADD_ALL_TESTS(test_property_merge, OSSL_NELEM(merge_tests)); ADD_TEST(test_property_defn_cache); -- 2.47.2