50 lines
1.7 KiB
Diff
50 lines
1.7 KiB
Diff
From 123d03dca47c4d8e0dc896dd8c5732329e6acffe Mon Sep 17 00:00:00 2001
|
||
From: Paul Eggert <eggert@cs.ucla.edu>
|
||
Date: Sat, 1 Jul 2023 11:31:41 -0700
|
||
Subject: [PATCH] =?UTF-8?q?who:=20don=E2=80=99t=20crash=20if=20clock=20gyr?=
|
||
=?UTF-8?q?ates?=
|
||
MIME-Version: 1.0
|
||
Content-Type: text/plain; charset=UTF-8
|
||
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.
|
||
|
||
Reference:https://github.com/coreutils/coreutils/commit/123d03dca47c4d8e0dc896dd8c5732329e6acffe
|
||
Conflict:Context adaptation
|
||
|
||
---
|
||
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-2018: see if this assert is still required in order
|
||
- to suppress gcc's unwarranted -Wformat-length= warning. */
|
||
- assert (seconds_idle / (60 * 60) < 24);
|
||
sprintf (idle_hhmm, "%02d:%02d",
|
||
seconds_idle / (60 * 60),
|
||
(seconds_idle % (60 * 60)) / 60);
|
||
--
|
||
2.27.0
|
||
|