From 0a7a71a4f24b4608662b4532bd17aef758f049fd Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 5 Aug 2023 11:16:12 -0700 Subject: [PATCH] readutmp: anticipate Y2038 hack for utmp * lib/readutmp.c (struct utmpx32): Use unsigned int for tv_sec, not int, as that is more likely to work after 2038. Suggested by Andreas Schwab in: https://sourceware.org/pipermail/libc-alpha/2023-August/150661.html --- ChangeLog | 6 ++++++ lib/readutmp.c | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e1437b1b41..80ac7184d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2023-08-05 Paul Eggert + readutmp: anticipate Y2038 hack for utmp + * lib/readutmp.c (struct utmpx32): Use unsigned int for tv_sec, + not int, as that is more likely to work after 2038. + Suggested by Andreas Schwab in: + https://sourceware.org/pipermail/libc-alpha/2023-August/150661.html + diffseq: simplify lint removal * lib/diffseq.h (IF_LINT): Remove. Instead, always ignore the diagnostic, as that’s simpler diff --git a/lib/readutmp.c b/lib/readutmp.c index ac1c851e97..b8eba076fa 100644 --- a/lib/readutmp.c +++ b/lib/readutmp.c @@ -491,7 +491,12 @@ copy_utmp_entry (STRUCT_UTMP *dst, STRUCT_UTMP *src) int ut_session; /* Session ID, used for windowing. */ struct { - int tv_sec; /* Seconds. */ + /* Seconds. Unsigned not signed, as glibc did not exist before 1970, + and if the format is still in use after 2038 its timestamps + will surely have the sign bit on. This hack stops working + at 2106-02-07 06:28:16 UTC. */ + unsigned int tv_sec; + int tv_usec; /* Microseconds. */ } ut_tv; /* Time entry was made. */ int ut_addr_v6[4]; /* Internet address of remote host. */ -- 2.39.5