diff options
author | Richard Levitte <levitte@openssl.org> | 2017-08-17 18:03:22 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2017-08-18 09:52:01 +0200 |
commit | fdf9450f4266971035ca5f87c46c3826b49b5757 (patch) | |
tree | acea43979a8fe5609e4fa7e2f800c4d384275c0f /test | |
parent | 8909c2ceeee2c1683f783d905f975bca8626ad33 (diff) | |
download | openssl-fdf9450f4266971035ca5f87c46c3826b49b5757.zip openssl-fdf9450f4266971035ca5f87c46c3826b49b5757.tar.gz openssl-fdf9450f4266971035ca5f87c46c3826b49b5757.tar.bz2 |
test/asn1_time_test.c: Better check of signed time_t
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4182)
Diffstat (limited to 'test')
-rw-r--r-- | test/asn1_time_test.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/test/asn1_time_test.c b/test/asn1_time_test.c index 897436c..c185ece 100644 --- a/test/asn1_time_test.c +++ b/test/asn1_time_test.c @@ -276,18 +276,31 @@ static int test_table_neg_64bit(int idx) int setup_tests(void) { + /* + * On platforms where |time_t| is an unsigned integer, t will be a + * positive number. + * + * We check if we're on a platform with a signed |time_t| with '!(t > 0)' + * because some compilers are picky if you do 't < 0', or even 't <= 0' + * if |t| is unsigned. + */ time_t t = -1; + /* + * On some platforms, |time_t| is signed, but a negative value is an + * error, and using it with gmtime() or localtime() generates a NULL. + * If that is the case, we can't perform tests on negative values. + */ struct tm *ptm = localtime(&t); ADD_ALL_TESTS(test_table_pos, OSSL_NELEM(tbl_testdata_pos)); - if (ptm != NULL) { + if (!(t > 0) && ptm != NULL) { TEST_info("Adding negative-sign time_t tests"); ADD_ALL_TESTS(test_table_neg, OSSL_NELEM(tbl_testdata_neg)); } if (sizeof(time_t) > sizeof(uint32_t)) { TEST_info("Adding 64-bit time_t tests"); ADD_ALL_TESTS(test_table_pos_64bit, OSSL_NELEM(tbl_testdata_pos_64bit)); - if (ptm != NULL) { + if (!(t > 0) && ptm != NULL) { TEST_info("Adding negative-sign 64-bit time_t tests"); ADD_ALL_TESTS(test_table_neg_64bit, OSSL_NELEM(tbl_testdata_neg_64bit)); } |