]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
4852. [bug] Handle strftime() failing in isc_time_formatISO8601ms.
authorMark Andrews <marka@isc.org>
Mon, 1 Jan 2018 23:46:41 +0000 (10:46 +1100)
committerMark Andrews <marka@isc.org>
Mon, 1 Jan 2018 23:46:41 +0000 (10:46 +1100)
                        Add REQUIRE's and INSIST's to isc_time_formattimestamp,
                        isc_time_formathttptimestamp, isc_time_formatISO8601,
                        isc_time_formatISO8601ms. [RT #46892]

CHANGES
lib/isc/unix/time.c
lib/isc/win32/time.c

diff --git a/CHANGES b/CHANGES
index bedf243ac6933fa3e274020c685434a3739400aa..345288bf32ebead5199479adb9d15e66c4b54d6d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,8 @@
+4852.  [bug]           Handle strftime() failing in isc_time_formatISO8601ms.
+                       Add REQUIRE's and INSIST's to isc_time_formattimestamp,
+                       isc_time_formathttptimestamp, isc_time_formatISO8601,
+                       isc_time_formatISO8601ms. [RT #46892]
+
 4851.  [port]          Support using kyua as well as atf-run to run the unit
                        tests. [RT #46853]
 
index 5c7958fa428065b6d0fa59d4ba57f9cac8226c11..2c7239fa8f4d2e51f9a8af2472a511abf371c95a 100644 (file)
@@ -381,6 +381,9 @@ isc_time_formattimestamp(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;
@@ -406,6 +409,9 @@ isc_time_formathttptimestamp(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);
 
        /*
@@ -429,6 +435,7 @@ isc_time_parsehttptimestamp(char *buf, isc_time_t *t) {
 
        REQUIRE(buf != NULL);
        REQUIRE(t != NULL);
+
        p = isc_tm_strptime(buf, "%a, %d %b %Y %H:%M:%S", &t_tm);
        if (p == NULL)
                return (ISC_R_UNEXPECTED);
@@ -447,6 +454,9 @@ isc_time_formatISO8601(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;
@@ -466,6 +476,9 @@ isc_time_formatISO8601ms(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;
@@ -475,8 +488,8 @@ isc_time_formatISO8601ms(const isc_time_t *t, char *buf, unsigned int len) {
        flen = strftime(buf, len, "%Y-%m-%dT%H:%M:%SZ", gmtime(&now));
 #endif
        INSIST(flen < len);
-       if (flen == len - 5) {
-               flen -= 1; /* rewind one character */
+       if (flen > 0U && len - flen >= 5) {
+               flen -= 1; /* rewind one character (Z) */
                snprintf(buf + flen, len - flen, ".%03uZ",
                         t->nanoseconds / NS_PER_MS);
        }
index e6dcf693c398f7b2e4d8970ae9730327c9f83ba3..1ae189580798df135f0c243791f4f0b956f30a10 100644 (file)
@@ -272,7 +272,10 @@ isc_time_formattimestamp(const isc_time_t *t, char *buf, unsigned int len) {
        char DateBuf[50];
        char TimeBuf[50];
 
+       REQUIRE(t != NULL);
+       REQUIRE(buf != NULL);
        REQUIRE(len > 0);
+
        if (FileTimeToLocalFileTime(&t->absolute, &localft) &&
            FileTimeToSystemTime(&localft, &st)) {
                GetDateFormat(LOCALE_USER_DEFAULT, 0, &st, "dd-MMM-yyyy",
@@ -296,7 +299,10 @@ isc_time_formathttptimestamp(const isc_time_t *t, char *buf, unsigned int len) {
 
 /* strftime() format: "%a, %d %b %Y %H:%M:%S GMT" */
 
+       REQUIRE(t != NULL);
+       REQUIRE(buf != NULL);
        REQUIRE(len > 0);
+
        if (FileTimeToSystemTime(&t->absolute, &st)) {
                GetDateFormat(LOCALE_USER_DEFAULT, 0, &st,
                              "ddd',' dd MMM yyyy", DateBuf, 50);
@@ -318,6 +324,7 @@ isc_time_parsehttptimestamp(char *buf, isc_time_t *t) {
 
        REQUIRE(buf != NULL);
        REQUIRE(t != NULL);
+
        p = isc_tm_strptime(buf, "%a, %d %b %Y %H:%M:%S", &t_tm);
        if (p == NULL)
                return (ISC_R_UNEXPECTED);
@@ -336,7 +343,10 @@ isc_time_formatISO8601(const isc_time_t *t, char *buf, unsigned int len) {
 
        /* strtime() format: "%Y-%m-%dT%H:%M:%SZ" */
 
+       REQUIRE(t != NULL);
+       REQUIRE(buf != NULL);
        REQUIRE(len > 0);
+
        if (FileTimeToSystemTime(&t->absolute, &st)) {
                GetDateFormat(LOCALE_NEUTRAL, 0, &st, "yyyy-MM-dd",
                              DateBuf, 50);
@@ -357,7 +367,10 @@ isc_time_formatISO8601ms(const isc_time_t *t, char *buf, unsigned int len) {
 
        /* strtime() format: "%Y-%m-%dT%H:%M:%S.SSSZ" */
 
+       REQUIRE(t != NULL);
+       REQUIRE(buf != NULL);
        REQUIRE(len > 0);
+
        if (FileTimeToSystemTime(&t->absolute, &st)) {
                GetDateFormat(LOCALE_NEUTRAL, 0, &st, "yyyy-MM-dd",
                              DateBuf, 50);