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 <thomas@t-8ch.de>
This commit is contained in:
Thomas Weißschuh 2023-06-28 07:21:38 +02:00
parent 2b48beb44e
commit a8d0195462
2 changed files with 2 additions and 2 deletions

View file

@ -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)

View file

@ -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]