if (!TEST_int64_t_eq(ps, - expected_secs))
goto err;
- /*
- * OPENSSL_gmtime[diff/adj] use struct tm as input to public
- * API. However unlike most platform provided time conversion
- * functions, it does not validate the values in the tm as per C99
- * spec before attempting to use it. It also only partly limits
- * what it will convert to the ASN1_TIME date range, and does not
- * support the entire range. The define below makes tests that
- * fail pass to match the current behaviour.
- */
-#define ITS_TRADITION_THAT_MAKES_IT_OK
-
/*
* Struct tm permits second 60 in C99. As neither of the values
* tested here are actually a for realsies leap second, (We do not
ps = psec;
if (!TEST_false((pd == expected_days + 1 && ps == 0))) {
TEST_info("OPENSSL_gmtime_diff incorrectly includes bogus leap second");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
} else {
if (!TEST_int64_t_eq(pd, expected_days))
goto err;
ps = psec;
if (!TEST_false((pd == expected_days && ps == expected_secs - 60))) {
TEST_info("OPENSSL_gmtime_diff incorrectly includes bogus leap second");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
} else {
if (!TEST_int64_t_eq(pd, expected_days))
goto err;
ps = psec;
if (!TEST_false((pd == expected_days + 1 && ps == 0))) {
TEST_info("OPENSSL_gmtime_diff incorrectly includes bogus leap second");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
} else {
if (!TEST_int64_t_eq(pd, expected_days))
goto err;
min_tm.tm_mon = 12;
if (!TEST_false(OPENSSL_gmtime_diff(&pday, &psec, &min_tm, &max_tm))) {
TEST_info("OPENSSL_gmtime_diff incorrectly allows month 12");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
min_tm.tm_mon = saved_value;
min_tm.tm_mon = -1;
if (!TEST_false(OPENSSL_gmtime_diff(&pday, &psec, &min_tm, &max_tm))) {
TEST_info("OPENSSL_gmtime_diff incorrectly allows month -1");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
min_tm.tm_mon = saved_value;
min_tm.tm_mday = 32;
if (!TEST_false(OPENSSL_gmtime_diff(&pday, &psec, &min_tm, &max_tm))) {
TEST_info("OPENSSL_gmtime_diff incorrectly allows the 32nd of January");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
min_tm.tm_mday = saved_value;
min_tm.tm_mday = 0;
if (!TEST_false(OPENSSL_gmtime_diff(&pday, &psec, &min_tm, &max_tm))) {
TEST_info("OPENSSL_gmtime_diff incorrectly allows the 0th of January");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
min_tm.tm_mday = saved_value;
min_tm.tm_hour = 24;
if (!TEST_false(OPENSSL_gmtime_diff(&pday, &psec, &min_tm, &max_tm))) {
TEST_info("OPENSSL_gmtime_diff incorrectly allows hour 24");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
min_tm.tm_hour = saved_value;
min_tm.tm_hour = -1;
if (!TEST_false(OPENSSL_gmtime_diff(&pday, &psec, &min_tm, &max_tm))) {
TEST_info("OPENSSL_gmtime_diff incorrectly allows hour -1");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
min_tm.tm_hour = saved_value;
min_tm.tm_min = 60;
if (!TEST_false(OPENSSL_gmtime_diff(&pday, &psec, &min_tm, &max_tm))) {
TEST_info("OPENSSL_gmtime_diff incorrectly allows minute 60");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
min_tm.tm_min = saved_value;
min_tm.tm_min = -1;
if (!TEST_false(OPENSSL_gmtime_diff(&pday, &psec, &min_tm, &max_tm))) {
TEST_info("OPENSSL_gmtime_diff incorrectly allows minute -1");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
min_tm.tm_min = saved_value;
min_tm.tm_sec = -1;
if (!TEST_false(OPENSSL_gmtime_diff(&pday, &psec, &min_tm, &max_tm))) {
TEST_info("OPENSSL_gmtime_diff incorrectly allows second -1");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
min_tm.tm_sec = saved_value;
min_tm.tm_sec = 61; /* Not allowed per C99. */
if (!TEST_false(OPENSSL_gmtime_diff(&pday, &psec, &min_tm, &max_tm))) {
TEST_info("OPENSSL_gmtime_diff incorrectly allows second 61");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
min_tm.tm_sec = saved_value;
/* Adj should work for year 0000. */
if (!TEST_true(OPENSSL_gmtime_adj(©, 0, 0))) {
TEST_info("OPENSSL_gmtime_adj unexpectedly failed for year 0");
- /* ... except that it doesn't */
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
memcpy(©, &tm, sizeof(tm));
"%d days and %ld seconds", - days, - seconds);
goto err;
}
- /*
- * Adj currently fails for result times before 1900, but can
- * start with a time before that, as long as the result is
- * before year 10000.
- */
if (!TEST_true(OPENSSL_gmtime_adj(©, - days, - seconds))) {
TEST_info("OPENSSL_gmtime_adj unexpectedly failed for "
"%d days and %ld seconds", - days, - seconds);
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
if (!TEST_mem_eq(©, sizeof(copy), &tm, sizeof(tm))) {
TEST_info("tm does not have expected value after adj of "
"%d days and %ld seconds", days, seconds);
goto err;
}
-#endif
seconds = (long) ((MAX_POSIX_TIME - MIN_POSIX_TIME) % (int64_t)LONG_MAX);
days = (int) ((MAX_POSIX_TIME - MIN_POSIX_TIME
- (int64_t)seconds) / SECS_PER_DAY);
if (!TEST_true(OPENSSL_gmtime_adj(©, days, seconds))) {
TEST_info("OPENSSL_gmtime_adj unexpectedly failed for "
"%d days and %ld seconds", - days, - seconds);
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
if (!TEST_true(OPENSSL_gmtime_adj(©, - days, - seconds))) {
TEST_info("OPENSSL_gmtime_adj unexpectedly failed for "
"%d days and %ld seconds", - days, - seconds);
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
if (!TEST_mem_eq(©, sizeof(copy), &tm, sizeof(tm))) {
TEST_info("tm does not have expected value after adj of "
"%d days and %ld seconds", days, seconds);
goto err;
}
-#endif
/* 99991231235959Z - MAX_POSIX_TIME. */
memset(&tm, 0, sizeof(tm));
tm.tm_mon = 12;
if (!TEST_false(OPENSSL_gmtime_adj(&tm, 0, 0))) {
TEST_info("OPENSSL_gmtime_adj incorrectly allows month 12");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
tm.tm_mon = -1;
if (!TEST_false(OPENSSL_gmtime_adj(&tm, 0, 0))) {
TEST_info("OPENSSL_gmtime_adj incorrectly allows month -1");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
tm.tm_mon = 0;
tm.tm_mday = 32;
if (!TEST_false(OPENSSL_gmtime_adj(&tm, 0, 0))) {
TEST_info("OPENSSL_gmtime_adj incorrectly allows 32nd of January");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
tm.tm_mday = 0;
if (!TEST_false(OPENSSL_gmtime_adj(&tm, 0, 0))) {
TEST_info("OPENSSL_gmtime_adj incorrectly allows the 0th of January");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
tm.tm_mday = 1;
tm.tm_hour = 24;
if (!TEST_false(OPENSSL_gmtime_adj(&tm, 0, 0))) {
TEST_info("OPENSSL_gmtime_adj incorrectly allows hour 24");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
tm.tm_hour = -1;
if (!TEST_false(OPENSSL_gmtime_adj(&tm, 0, 0))) {
TEST_info("OPENSSL_gmtime_adj incorrectly allows hour -1");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
tm.tm_hour = 0;
tm.tm_min = 60;
if (!TEST_false(OPENSSL_gmtime_adj(&tm, 0, 0))) {
TEST_info("OPENSSL_gmtime_adj incorrectly allows minute 60");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
tm.tm_min = -1;
if (!TEST_false(OPENSSL_gmtime_adj(&tm, 0, 0))) {
TEST_info("OPENSSL_gmtime_adj incorrectly allows minute -1");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
tm.tm_min = 0;
tm.tm_sec = -1;
if (!TEST_false(OPENSSL_gmtime_adj(&tm, 0, 0))) {
TEST_info("OPENSSL_gmtime_adj incorrectly allows second -1");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
tm.tm_sec = 61; /* Not allowed per C99. */
if (!TEST_false(OPENSSL_gmtime_adj(&tm, 0, 0))) {
TEST_info("OPENSSL_gmtime_adj incorrectly allows second 61");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
tm.tm_sec = 0;
if (!TEST_false(OPENSSL_gmtime_adj(©, 0, 0))) {
if (!TEST_mem_eq(©, sizeof(copy), &tm, sizeof(tm))) {
TEST_info("OPENSSL_gmtime_adj incorrectly accepted a bogus leap second");
-#if !defined(ITS_TRADITION_THAT_MAKES_IT_OK)
goto err;
-#endif
}
}
tm.tm_sec = 0;