[openssl] master update
Dr. Paul Dale
pauli at openssl.org
Sat May 22 05:30:54 UTC 2021
The branch master has been updated
via 862497a9183412d50615afe2d2bfde1ac6c7ffa8 (commit)
from b54611922b5eb760bd64de0c8edfeb13ae81fa65 (commit)
- Log -----------------------------------------------------------------
commit 862497a9183412d50615afe2d2bfde1ac6c7ffa8
Author: Pauli <pauli at openssl.org>
Date: Fri May 21 11:19:30 2021 +1000
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 at openssl.org>
Reviewed-by: Matt Caswell <matt at openssl.org>
Reviewed-by: Richard Levitte <levitte at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15396)
-----------------------------------------------------------------------
Summary of changes:
crypto/property/property_parse.c | 10 +++--
test/property_test.c | 85 +++++++++++++++++++---------------------
2 files changed, 48 insertions(+), 47 deletions(-)
diff --git a/crypto/property/property_parse.c b/crypto/property/property_parse.c
index aab8cbe8a4..6352def860 100644
--- a/crypto/property/property_parse.c
+++ b/crypto/property/property_parse.c
@@ -658,11 +658,15 @@ static void put_str(const char *str, char **buf, size_t *remain, size_t *needed)
}
}
-static void put_num(int val, char **buf, size_t *remain, size_t *needed)
+static void put_num(int64_t val, char **buf, size_t *remain, size_t *needed)
{
- int tmpval = val;
+ int64_t tmpval = val;
size_t len = 1;
+ if (tmpval < 0) {
+ len++;
+ tmpval = -tmpval;
+ }
for (; tmpval > 9; len++, tmpval /= 10);
*needed += len;
@@ -670,7 +674,7 @@ static void put_num(int val, char **buf, size_t *remain, size_t *needed)
if (*remain == 0)
return;
- BIO_snprintf(*buf, *remain, "%d", val);
+ BIO_snprintf(*buf, *remain, "%lld", (long long int)val);
if (*remain < len) {
*buf += *remain;
*remain = 0;
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;
}
More information about the openssl-commits
mailing list