From 123d03dca47c4d8e0dc896dd8c5732329e6acffe Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 1 Jul 2023 11:31:41 -0700 Subject: [PATCH] =?utf8?q?who:=20don=E2=80=99t=20crash=20if=20clock=20gyra?= =?utf8?q?tes?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * src/who.c (idle_string): Avoid signed integer overflow if the superuser messes with the clock in bizarre ways. Remove an ‘assume’ that wasn’t correct under this scenario. --- src/who.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/who.c b/src/who.c index 362408a42..cff1b822b 100644 --- a/src/who.c +++ b/src/who.c @@ -189,17 +189,16 @@ idle_string (time_t when, time_t boottime) if (now == TYPE_MINIMUM (time_t)) time (&now); - if (boottime < when && now - 24 * 60 * 60 < when && when <= now) + int seconds_idle; + if (boottime < when && when <= now + && ! INT_SUBTRACT_WRAPV (now, when, &seconds_idle) + && seconds_idle < 24 * 60 * 60) { - int seconds_idle = now - when; if (seconds_idle < 60) return " . "; else { static char idle_hhmm[IDLESTR_LEN]; - /* FIXME-in-2024: see if this is still required in order - to suppress gcc's unwarranted -Wformat-length= warning. */ - assume (seconds_idle / (60 * 60) < 24); sprintf (idle_hhmm, "%02d:%02d", seconds_idle / (60 * 60), (seconds_idle % (60 * 60)) / 60); -- 2.11.4.GIT