summaryrefslogtreecommitdiffstats
path: root/test/property_test.c
diff options
context:
space:
mode:
authorPauli <pauli@openssl.org>2021-09-30 11:35:32 +1000
committerPauli <pauli@openssl.org>2021-10-09 23:29:13 +1000
commit747d142318c5c9ecd80de3f061f54d7af4189039 (patch)
tree805ccbf0f987677744e8e043fdcb40708da0ddd5 /test/property_test.c
parent8e61832ed7f59c15da003aa86aeaa4e5f44df711 (diff)
test: add failure testing for property parsing
Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/16716)
Diffstat (limited to 'test/property_test.c')
-rw-r--r--test/property_test.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/property_test.c b/test/property_test.c
index 6cc8eec138..c23ddb0f99 100644
--- a/test/property_test.c
+++ b/test/property_test.c
@@ -146,6 +146,52 @@ static int test_property_query_value_create(void)
}
static const struct {
+ int query;
+ const char *ps;
+} parse_error_tests[] = {
+ { 0, "n=1, n=1" }, /* duplicate name */
+ { 0, "n=1, a=hi, n=1" }, /* duplicate name */
+ { 1, "n=1, a=bye, ?n=0" }, /* duplicate name */
+ { 0, "a=abc,#@!, n=1" }, /* non-ASCII character located */
+ { 1, "a='Hello" }, /* Unterminated string */
+ { 0, "a=\"World" }, /* Unterminated string */
+ { 1, "a=2, n=012345678" }, /* Bad octal digit */
+ { 0, "n=0x28FG, a=3" }, /* Bad hex digit */
+ { 0, "n=145d, a=2" }, /* Bad decimal digit */
+ { 1, "@='hello'" }, /* Invalid name */
+ { 1, "n0123456789012345678901234567890123456789"
+ "0123456789012345678901234567890123456789"
+ "0123456789012345678901234567890123456789"
+ "0123456789012345678901234567890123456789=yes" }, /* Name too long */
+ { 0, ".n=3" }, /* Invalid name */
+ { 1, "fnord.fnord.=3" } /* Invalid name */
+};
+
+static int test_property_parse_error(int n)
+{
+ OSSL_METHOD_STORE *store;
+ OSSL_PROPERTY_LIST *p = NULL;
+ int r = 0;
+ const char *ps;
+
+ if (!TEST_ptr(store = ossl_method_store_new(NULL))
+ || !add_property_names("a", "n", NULL))
+ goto err;
+ ps = parse_error_tests[n].ps;
+ if (parse_error_tests[n].query) {
+ if (!TEST_ptr_null(p = ossl_parse_query(NULL, ps, 1)))
+ goto err;
+ } else if (!TEST_ptr_null(p = ossl_parse_property(NULL, ps))) {
+ goto err;
+ }
+ r = 1;
+ err:
+ ossl_property_free(p);
+ ossl_method_store_free(store);
+ return r;
+}
+
+static const struct {
const char *q_global;
const char *q_local;
const char *prop;
@@ -493,6 +539,7 @@ 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_parse_error, OSSL_NELEM(parse_error_tests));
ADD_ALL_TESTS(test_property_merge, OSSL_NELEM(merge_tests));
ADD_TEST(test_property_defn_cache);
ADD_ALL_TESTS(test_definition_compares, OSSL_NELEM(definition_tests));