]> git.ipfire.org Git - thirdparty/util-linux.git/commit
lib/timeutils: ISO_8601_BUFSIZ too small
authorJ William Piggott <elseifthen@gmx.com>
Tue, 26 Sep 2017 00:56:06 +0000 (20:56 -0400)
committerKarel Zak <kzak@redhat.com>
Thu, 14 Dec 2017 14:32:24 +0000 (15:32 +0100)
commita62e5dacff4fa8c9f634680e6989a2fde31b71db
tree65ad9c949b2dc95cd13241a3e8cef8d05bf506fe
parent12378f1bacb2a3104042eea5ea0633f796c7ee87
lib/timeutils: ISO_8601_BUFSIZ too small

Although iso-8601 specifies years as 4 digits, it allows
them to be wider.

The current POSIX year width is limited by 'int tm_year'
at 10 digits plus a negative sign.

That, and the possibility of nanosecond time makes the
widest POSIX iso-8601 time 41 characters. Plus the \0
string terminator yields a buffer size of 42.

Before truncated output:
/sbin/hwclock --utc --noadjfile --predict --date '-2147483765 years'
-2147481748-09-25 20:29:45.0000

Patched:
./hwclock --utc --noadjfile --predict --date '-2147483765 years'
-2147481748-09-25 20:17:21.000000-0456

./hwclock --utc --noadjfile --predict --date '-2147483766 years'
hwclock: invalid date '-2147483766 years'

Comparable to coreutils 'date' command:
date -Ins --date '-2147483765 years'
-2147481748-09-25T19:49:31,578899297-0456

date -Ins --date '-2147483766 years'
date: invalid date '-2147483766 years'

The 'date' output illustrates the full 41 character POSIX iso-8601

Signed-off-by: J William Piggott <elseifthen@gmx.com>
include/timeutils.h