]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
utmpdump: validate subsecond granularity
authorThomas Weißschuh <thomas@t-8ch.de>
Wed, 28 Jun 2023 05:21:38 +0000 (07:21 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Wed, 28 Jun 2023 12:50:49 +0000 (14:50 +0200)
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>
login-utils/utmpdump.c
tests/expected/utmp/utmpdump-subsecond

index a0ff2b170d967c5d2286a433e3c8071b2d561721..eb3159ee2b43656c1d6961e4560a16bf109353f7 100644 (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)
index 67d2cf85903e356f74c6c3246012810f14090476..02990c7449fae0c00b878e9e77432218f4163671 100644 (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]