summaryrefslogtreecommitdiffstats
path: root/test/property_test.c
diff options
context:
space:
mode:
authorPauli <pauli@openssl.org>2021-05-21 11:19:30 +1000
committerPauli <pauli@openssl.org>2021-05-22 15:30:26 +1000
commit862497a9183412d50615afe2d2bfde1ac6c7ffa8 (patch)
treebd8d249f0cab7c79cb1daeebe136c454d1554bf2 /test/property_test.c
parentb54611922b5eb760bd64de0c8edfeb13ae81fa65 (diff)
property: convert integers to strings properly.
The int64_t type was converted to int (truncation). Negative values were not handled at all. Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15396)
Diffstat (limited to 'test/property_test.c')
-rw-r--r--test/property_test.c85
1 files changed, 41 insertions, 44 deletions
diff --git a/test/property_test.c b/test/property_test.c
index 94540bc776..6cc8eec138 100644
--- a/test/property_test.c
+++ b/test/property_test.c
@@ -435,54 +435,51 @@ err:
return ret;
}
-static int test_property_list_to_string(void)
+static struct {
+ const char *in;
+ const char *out;
+} to_string_tests[] = {
+ { "fips=yes", "fips=yes" },
+ { "fips!=yes", "fips!=yes" },
+ { "fips = yes", "fips=yes" },
+ { "fips", "fips=yes" },
+ { "fips=no", "fips=no" },
+ { "-fips", "-fips" },
+ { "?fips=yes", "?fips=yes" },
+ { "fips=yes,provider=fips", "fips=yes,provider=fips" },
+ { "fips = yes , provider = fips", "fips=yes,provider=fips" },
+ { "fips=yes,provider!=fips", "fips=yes,provider!=fips" },
+ { "fips=yes,?provider=fips", "fips=yes,?provider=fips" },
+ { "fips=yes,-provider", "fips=yes,-provider" },
+ /* foo is an unknown internal name */
+ { "foo=yes,fips=yes", "fips=yes"},
+ { "", "" },
+ { "fips=3", "fips=3" },
+ { "fips=-3", "fips=-3" },
+ { NULL, "" }
+};
+
+static int test_property_list_to_string(int i)
{
OSSL_PROPERTY_LIST *pl = NULL;
int ret = 0;
- struct props_list_str {
- const char *in;
- const char *out;
- } props[] = {
- { "fips=yes", "fips=yes" },
- { "fips!=yes", "fips!=yes" },
- { "fips = yes", "fips=yes" },
- { "fips", "fips=yes" },
- { "fips=no", "fips=no" },
- { "-fips", "-fips" },
- { "?fips=yes", "?fips=yes" },
- { "fips=yes,provider=fips", "fips=yes,provider=fips" },
- { "fips = yes , provider = fips", "fips=yes,provider=fips" },
- { "fips=yes,provider!=fips", "fips=yes,provider!=fips" },
- { "fips=yes,?provider=fips", "fips=yes,?provider=fips" },
- { "fips=yes,-provider", "fips=yes,-provider" },
- /* foo is an unknown internal name */
- { "foo=yes,fips=yes", "fips=yes"},
- { "", "" },
- { NULL, "" }
- };
- size_t i, bufsize;
+ size_t bufsize;
char *buf = NULL;
- for (i = 0; i < OSSL_NELEM(props); i++) {
- if (props[i].in != NULL
- && !TEST_ptr(pl = ossl_parse_query(NULL, props[i].in, 1)))
- goto err;
- bufsize = ossl_property_list_to_string(NULL, pl, NULL, 0);
- if (!TEST_size_t_gt(bufsize, 0))
- goto err;
- buf = OPENSSL_malloc(bufsize);
- if (!TEST_ptr(buf)
- || !TEST_size_t_eq(ossl_property_list_to_string(NULL, pl, buf,
- bufsize),
- bufsize)
- || !TEST_str_eq(props[i].out, buf)
- || !TEST_size_t_eq(bufsize, strlen(props[i].out) + 1))
- goto err;
- OPENSSL_free(buf);
- buf = NULL;
- ossl_property_free(pl);
- pl = NULL;
- }
+ if (to_string_tests[i].in != NULL
+ && !TEST_ptr(pl = ossl_parse_query(NULL, to_string_tests[i].in, 1)))
+ goto err;
+ bufsize = ossl_property_list_to_string(NULL, pl, NULL, 0);
+ if (!TEST_size_t_gt(bufsize, 0))
+ goto err;
+ buf = OPENSSL_malloc(bufsize);
+ if (!TEST_ptr(buf)
+ || !TEST_size_t_eq(ossl_property_list_to_string(NULL, pl, buf,
+ bufsize),
+ bufsize)
+ || !TEST_str_eq(to_string_tests[i].out, buf)
+ || !TEST_size_t_eq(bufsize, strlen(to_string_tests[i].out) + 1))
+ goto err;
ret = 1;
err:
@@ -503,6 +500,6 @@ int setup_tests(void)
ADD_TEST(test_property);
ADD_TEST(test_query_cache_stochastic);
ADD_TEST(test_fips_mode);
- ADD_TEST(test_property_list_to_string);
+ ADD_ALL_TESTS(test_property_list_to_string, OSSL_NELEM(to_string_tests));
return 1;
}