diff options
author | Theo Buehler <tb@cvs.openbsd.org> | 2024-05-25 18:59:04 +0000 |
---|---|---|
committer | Theo Buehler <tb@cvs.openbsd.org> | 2024-05-25 18:59:04 +0000 |
commit | 1b0a4b1e818581c76a1a177dfb7faafa660b23dd (patch) | |
tree | 6ed7bb7e786dc921e0877ce133bce2e3833bae65 /regress/lib | |
parent | f8d1d1b7e853717229fe0a63e00a32be219ac014 (diff) |
Eliminate last timegm() correctly this time
Also add a test case with a generalized time representing the moment
one second past the 32-bit epoch wrap.
Diffstat (limited to 'regress/lib')
-rw-r--r-- | regress/lib/libcrypto/asn1/asn1time.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/regress/lib/libcrypto/asn1/asn1time.c b/regress/lib/libcrypto/asn1/asn1time.c index 95c5d24dba6..b11a8923008 100644 --- a/regress/lib/libcrypto/asn1/asn1time.c +++ b/regress/lib/libcrypto/asn1/asn1time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asn1time.c,v 1.28 2024/05/25 12:47:25 tb Exp $ */ +/* $OpenBSD: asn1time.c,v 1.29 2024/05/25 18:59:03 tb Exp $ */ /* * Copyright (c) 2015 Joel Sing <jsing@openbsd.org> * Copyright (c) 2024 Google Inc. @@ -121,6 +121,18 @@ static const struct asn1_time_test asn1_gentime_tests[] = { 0x5a, }, }, + { + /* 1 second after the 32-bit epoch wraps. */ + .str = "20380119031408Z", + .data = "20380119031408Z", + .time = 2147483648LL, + .der = { + 0x18, 0x0f, 0x32, 0x30, 0x33, 0x38, 0x30, 0x31, + 0x31, 0x39, 0x30, 0x33, 0x31, 0x34, 0x30, 0x38, + 0x5a, + }, + + }, }; static const struct asn1_time_test asn1_utctime_tests[] = { @@ -280,6 +292,7 @@ asn1_gentime_test(int test_no, const struct asn1_time_test *att) const unsigned char *der; unsigned char *p = NULL; ASN1_GENERALIZEDTIME *gt = NULL; + time_t t; int failure = 1; int len; struct tm tm; @@ -307,11 +320,18 @@ asn1_gentime_test(int test_no, const struct asn1_time_test *att) goto done; } - if (timegm(&tm) != att->time) { + if (!OPENSSL_timegm(&tm, &t)) { /* things with crappy time_t should die in fire */ - int64_t a = timegm(&tm); - int64_t b = att->time; - fprintf(stderr, "FAIL: test %d - times don't match, expected %lld got %lld\n", + fprintf(stderr, "FAIL: test %d - OPENSSL_timegm failed\n", + test_no); + } + + if (t != att->time) { + /* things with crappy time_t should die in fire */ + int64_t a = t, b = att->time; + + fprintf(stderr, "FAIL: test %d - times don't match, " + "expected %lld got %lld\n", test_no, (long long)b, (long long)a); goto done; } |