]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/timeutils.c: warn format_iso_time() overflow
authorJ William Piggott <elseifthen@gmx.com>
Sat, 9 Dec 2017 23:43:29 +0000 (18:43 -0500)
committerJ William Piggott <elseifthen@gmx.com>
Sat, 9 Dec 2017 23:43:29 +0000 (18:43 -0500)
Print a message when the format_iso_time() buffer is exceeded, because
there is more than one type of failure that returns -1.

Also remove the corresponding message from hwclock.c.

Signed-off-by: J William Piggott <elseifthen@gmx.com>
lib/timeutils.c
sys-utils/hwclock.c

index a7459d2b69823834529a1a7c83ea02cb4d6c66c8..9c286aebc663d3e34e6e3881cd7002c88a2e04dd 100644 (file)
@@ -410,14 +410,14 @@ static int format_iso_time(struct tm *tm, suseconds_t usec, int flags, char *buf
                               tm->tm_year + (long) 1900,
                               tm->tm_mon + 1, tm->tm_mday);
                if (len < 0 || (size_t) len > bufsz)
-                       return -1;
+                       goto err;
                bufsz -= len;
                p += len;
        }
 
        if ((flags & ISO_DATE) && (flags & ISO_TIME)) {
                if (bufsz < 1)
-                       return -1;
+                       goto err;
                *p++ = (flags & ISO_T) ? 'T' : ' ';
                bufsz--;
        }
@@ -426,7 +426,7 @@ static int format_iso_time(struct tm *tm, suseconds_t usec, int flags, char *buf
                len = snprintf(p, bufsz, "%02d:%02d:%02d", tm->tm_hour,
                               tm->tm_min, tm->tm_sec);
                if (len < 0 || (size_t) len > bufsz)
-                       return -1;
+                       goto err;
                bufsz -= len;
                p += len;
        }
@@ -434,14 +434,14 @@ static int format_iso_time(struct tm *tm, suseconds_t usec, int flags, char *buf
        if (flags & ISO_DOTUSEC) {
                len = snprintf(p, bufsz, ".%06ld", (long) usec);
                if (len < 0 || (size_t) len > bufsz)
-                       return -1;
+                       goto err;
                bufsz -= len;
                p += len;
 
        } else if (flags & ISO_COMMAUSEC) {
                len = snprintf(p, bufsz, ",%06ld", (long) usec);
                if (len < 0 || (size_t) len > bufsz)
-                       return -1;
+                       goto err;
                bufsz -= len;
                p += len;
        }
@@ -452,9 +452,12 @@ static int format_iso_time(struct tm *tm, suseconds_t usec, int flags, char *buf
                int zmin  = abs(tmin % 60);
                len = snprintf(p, bufsz, "%+03d:%02d", zhour,zmin);
                if (len < 0 || (size_t) len > bufsz)
-                       return -1;
+                       goto err;
        }
        return 0;
+ err:
+       warnx(_("format_iso_time: buffer overflow."));
+       return -1;
 }
 
 /* timeval to ISO 8601 */
index e5f90a44e90db39e25fc0b4734ed3d0f810d2580..71d2b17b76e87d422669b76d299cc57b9014452b 100644 (file)
@@ -556,10 +556,9 @@ display_time(struct timeval hwctime)
 {
        char buf[ISO_BUFSIZ];
 
-       if (strtimeval_iso(&hwctime, ISO_TIMESTAMP_DOT, buf, sizeof(buf))) {
-               warnx(_("iso-8601 format overflow"));
+       if (strtimeval_iso(&hwctime, ISO_TIMESTAMP_DOT, buf, sizeof(buf)))
                return EXIT_FAILURE;
-       }
+
        printf("%s\n", buf);
        return EXIT_SUCCESS;
 }