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 <elseifthen@gmx.com>
This commit is contained in:
J William Piggott 2017-12-09 18:43:29 -05:00
parent 2d9a0b0adb
commit 6cdc7b9c02
2 changed files with 11 additions and 9 deletions

View 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 */

View 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;
}