From: Thomas Weißschuh Date: Wed, 28 Jun 2023 05:21:38 +0000 (+0200) Subject: utmpdump: validate subsecond granularity X-Git-Tag: v2.40-rc1~350^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a8d0195462f81456f10bc593bcfa69c23d0928ca;p=thirdparty%2Futil-linux.git utmpdump: validate subsecond granularity tv_usec is only valid in the range [0, 999999]. If the file contains garbage data replace interpret it as "0" instead. Signed-off-by: Thomas Weißschuh --- diff --git a/login-utils/utmpdump.c b/login-utils/utmpdump.c index a0ff2b170d..eb3159ee2b 100644 --- a/login-utils/utmpdump.c +++ b/login-utils/utmpdump.c @@ -108,7 +108,7 @@ static void print_utline(struct utmpx *ut, FILE *out) addr_string = inet_ntop(AF_INET, &(ut->ut_addr_v6), buffer, sizeof(buffer)); tv.tv_sec = ut->ut_tv.tv_sec; - tv.tv_usec = ut->ut_tv.tv_usec; + tv.tv_usec = ut->ut_tv.tv_usec < (int32_t) USEC_PER_SEC ? ut->ut_tv.tv_usec : 0; if (strtimeval_iso(&tv, ISO_TIMESTAMP_COMMA_GT, time_string, sizeof(time_string)) != 0) diff --git a/tests/expected/utmp/utmpdump-subsecond b/tests/expected/utmp/utmpdump-subsecond index 67d2cf8590..02990c7449 100644 --- a/tests/expected/utmp/utmpdump-subsecond +++ b/tests/expected/utmp/utmpdump-subsecond @@ -1,4 +1,4 @@ last 9 is expected to disappear in conversion [7] [00010] [ipv6] [IPv6 ] [root ] [dns-server ] [2001:503:ba3e::2:30] [2013-08-28T20:30:40,123456+00:00] [8] [00011] [ipv6] [IPv6 ] [root ] [dns-server ] [2001:503:ba3e::2:30] [2013-08-28T20:40:50,999999+00:00] -[0] [00000] [ts/0] [nonvalid] [foo ] [zero ] [0.0.0.0 ] [2013-08-28T12:00:00,12345678+00:00] +[0] [00000] [ts/0] [nonvalid] [foo ] [zero ] [0.0.0.0 ] [2013-08-28T12:00:00,000000+00:00]