summaryrefslogtreecommitdiffstats
path: root/lib/timeutils.c
diff options
context:
space:
mode:
authorJ William Piggott2017-12-10 00:43:29 +0100
committerJ William Piggott2017-12-10 00:43:29 +0100
commit6cdc7b9c02b251120eb014c4dbc2387d47e7fb46 (patch)
tree527c8eca8184214d0d19403f55f4e94bc93364bd /lib/timeutils.c
parentlib/timeutils.c:strxxx_iso: do not wrap tm_year (diff)
downloadkernel-qcow2-util-linux-6cdc7b9c02b251120eb014c4dbc2387d47e7fb46.tar.gz
kernel-qcow2-util-linux-6cdc7b9c02b251120eb014c4dbc2387d47e7fb46.tar.xz
kernel-qcow2-util-linux-6cdc7b9c02b251120eb014c4dbc2387d47e7fb46.zip
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>
Diffstat (limited to 'lib/timeutils.c')
-rw-r--r--lib/timeutils.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/timeutils.c b/lib/timeutils.c
index a7459d2b6..9c286aebc 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 */