From a8d0195462f81456f10bc593bcfa69c23d0928ca Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Wed, 28 Jun 2023 07:21:38 +0200 Subject: [PATCH] utmpdump: validate subsecond granularity MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- login-utils/utmpdump.c | 2 +- tests/expected/utmp/utmpdump-subsecond | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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] -- 2.47.2