summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorPaul Dreik <github@pauldreik.se>2023-12-07 20:31:50 +0100
committerTomas Mraz <tomas@openssl.org>2024-01-18 20:58:03 +0100
commitc15a844156d9cc373b2f42c58034437a3c45f58c (patch)
treed4639ba0120b67eb06a3395cf97a86b448724c73 /test
parent141365d1b4ab9d2ea4c76938f83b26429f0fb8ad (diff)
add test for provoking integer overflow in ossl_asn1_time_from_tm
this needs a sanitized 64 bit time_t build to be detected (or possibly valgrind, trapv or similar) Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22976) (cherry picked from commit 017fd465a4f01323465823a3dcf318553365dfdd)
Diffstat (limited to 'test')
-rw-r--r--test/asn1_time_test.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/asn1_time_test.c b/test/asn1_time_test.c
index 3344b76eae..aa1aa79ebb 100644
--- a/test/asn1_time_test.c
+++ b/test/asn1_time_test.c
@@ -9,6 +9,7 @@
/* Time tests for the asn1 module */
+#include <limits.h>
#include <stdio.h>
#include <string.h>
@@ -443,6 +444,30 @@ static int convert_asn1_to_time_t(int idx)
return 1;
}
+/*
+ * this test is here to exercise ossl_asn1_time_from_tm
+ * with an integer year close to INT_MAX.
+ */
+static int convert_tm_to_asn1_time(void)
+{
+ /* we need 64 bit time_t */
+#if ((ULONG_MAX >> 31) >> 31) >= 1
+ time_t t;
+ ASN1_TIME *at;
+
+ if (sizeof(time_t) * CHAR_BIT >= 64) {
+ t = 67768011791126057ULL;
+ at = ASN1_TIME_set(NULL, t);
+ /*
+ * If ASN1_TIME_set returns NULL, it means it could not handle the input
+ * which is fine for this edge case.
+ */
+ ASN1_STRING_free(at);
+ }
+#endif
+ return 1;
+}
+
int setup_tests(void)
{
/*
@@ -479,5 +504,6 @@ int setup_tests(void)
ADD_ALL_TESTS(test_table_compare, OSSL_NELEM(tbl_compare_testdata));
ADD_TEST(test_time_dup);
ADD_ALL_TESTS(convert_asn1_to_time_t, OSSL_NELEM(asn1_to_utc));
+ ADD_TEST(convert_tm_to_asn1_time);
return 1;
}