From: J William Piggott Date: Sat, 9 Dec 2017 23:43:29 +0000 (-0500) Subject: lib/timeutils.c: warn format_iso_time() overflow X-Git-Tag: v2.32-rc1~135 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6cdc7b9c02b251120eb014c4dbc2387d47e7fb46;p=thirdparty%2Futil-linux.git lib/timeutils.c: warn format_iso_time() overflow 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 --- diff --git a/lib/timeutils.c b/lib/timeutils.c index a7459d2b69..9c286aebc6 100644 --- a/lib/timeutils.c +++ b/lib/timeutils.c @@ -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 */ diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c index e5f90a44e9..71d2b17b76 100644 --- a/sys-utils/hwclock.c +++ b/sys-utils/hwclock.c @@ -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; }