Commit 1e10ef06 authored by Mark Andrews's avatar Mark Andrews
Browse files

4855. [bug] isc_time_formatshorttimestamp produced incorrect

                        output. [RT #46938]
parent 7258b852
4855. [bug] isc_time_formatshorttimestamp produced incorrect
output. [RT #46938]
4854. [bug] query_synthcnamewildcard should stop generating the
response if query_synthwildcard fails. [RT #46939]
 
......
......@@ -182,6 +182,37 @@ ATF_TC_BODY(isc_time_formatISO8601Lms, tc) {
ATF_CHECK_STREQ(buf, "2015-12-13T01:46:40.123");
}
ATF_TC(isc_time_formatshorttimestamp);
ATF_TC_HEAD(isc_time_formatshorttimestamp, tc) {
atf_tc_set_md_var(tc, "descr",
"print UTC time as yyyymmddhhmmsssss");
}
ATF_TC_BODY(isc_time_formatshorttimestamp, tc) {
isc_result_t result;
isc_time_t t;
char buf[64];
setenv("TZ", "PST8PDT", 1);
result = isc_time_now(&t);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
/* check formatting: yyyymmddhhmmsssss */
memset(buf, 'X', sizeof(buf));
isc_time_formatshorttimestamp(&t, buf, sizeof(buf));
ATF_CHECK_EQ(strlen(buf), 17);
/* check time conversion correctness */
memset(buf, 'X', sizeof(buf));
isc_time_settoepoch(&t);
isc_time_formatshorttimestamp(&t, buf, sizeof(buf));
ATF_CHECK_STREQ(buf, "19700101000000000");
memset(buf, 'X', sizeof(buf));
isc_time_set(&t, 1450000000, 123000000);
isc_time_formatshorttimestamp(&t, buf, sizeof(buf));
ATF_CHECK_STREQ(buf, "20151213094640123");
}
/*
* Main
*/
......@@ -191,6 +222,6 @@ ATF_TP_ADD_TCS(tp) {
ATF_TP_ADD_TC(tp, isc_time_formatISO8601ms);
ATF_TP_ADD_TC(tp, isc_time_formatISO8601L);
ATF_TP_ADD_TC(tp, isc_time_formatISO8601Lms);
ATF_TP_ADD_TC(tp, isc_time_formatshorttimestamp);
return (atf_no_error());
}
......@@ -552,6 +552,9 @@ isc_time_formatshorttimestamp(const isc_time_t *t, char *buf, unsigned int len)
struct tm tm;
#endif
REQUIRE(t != NULL);
INSIST(t->nanoseconds < NS_PER_S);
REQUIRE(buf != NULL);
REQUIRE(len > 0);
now = (time_t)t->seconds;
......@@ -562,7 +565,6 @@ isc_time_formatshorttimestamp(const isc_time_t *t, char *buf, unsigned int len)
#endif
INSIST(flen < len);
if (flen > 0U && len - flen >= 5) {
flen -= 1; /* rewind one character (Z) */
snprintf(buf + flen, len - flen, "%03u",
t->nanoseconds / NS_PER_MS);
}
......
......@@ -442,7 +442,10 @@ isc_time_formatshorttimestamp(const isc_time_t *t, char *buf, unsigned int len)
/* strtime() format: "%Y%m%d%H%M%SSSS" */
REQUIRE(t != NULL);
REQUIRE(buf != NULL);
REQUIRE(len > 0);
if (FileTimeToSystemTime(&t->absolute, &st)) {
GetDateFormat(LOCALE_NEUTRAL, 0, &st, "yyyyMMdd",
DateBuf, 50);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment