From a17c001d6baf142413da6c31068a162ff87f92b3 Mon Sep 17 00:00:00 2001 From: Herman Semenoff Date: Tue, 17 Mar 2026 18:38:59 +0300 Subject: [PATCH] daemon: fix time() 32-bit overflow in 2038 year Replaced the use of time_t with struct timeval and time() with gettimeofday() for time handling to prevent overflow in 2038. References: - https://en.wikipedia.org/wiki/Year_2038_problem - https://www.gnu.org/software/gnulib/manual/html_node/Avoiding-the-year-2038-problem.html --- src/daemon/gpm.c | 2 +- src/daemon/selection_copy.c | 4 ++-- src/daemon/selection_paste.c | 11 +++++++---- src/headers/daemon.h | 3 ++- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/daemon/gpm.c b/src/daemon/gpm.c index 6806dce..90b8811 100644 --- a/src/daemon/gpm.c +++ b/src/daemon/gpm.c @@ -95,7 +95,7 @@ int fifofd=-1; int eventFlag=0; Gpm_Cinfo *cinfo[MAX_VC+1]; -time_t last_selection_time; +struct timeval last_selection_time; time_t opt_age_limit = 0; diff --git a/src/daemon/selection_copy.c b/src/daemon/selection_copy.c index 124c613..205f686 100644 --- a/src/daemon/selection_copy.c +++ b/src/daemon/selection_copy.c @@ -21,7 +21,7 @@ #include /* open */ #include /* close */ -#include /* time */ +#include /* gettimeofday */ #include "headers/message.h" /* messaging in gpm */ @@ -55,7 +55,7 @@ void selection_copy(int x1, int y1, int x2, int y2, int mode) if (mode < 3) { opt_aged = 0; - last_selection_time = time(0); + gettimeofday(&last_selection_time, NULL); } } diff --git a/src/daemon/selection_paste.c b/src/daemon/selection_paste.c index 6a9086e..3d31f8a 100644 --- a/src/daemon/selection_paste.c +++ b/src/daemon/selection_paste.c @@ -19,7 +19,7 @@ * ********/ -#include /* time */ +#include /* gettimeofday */ #include /* open */ #include /* close */ @@ -30,10 +30,13 @@ void selection_paste(void) { char c=3; int fd; + struct timeval now; - if (!opt_aged && (0 != opt_age_limit) && - (last_selection_time + opt_age_limit < time(0))) { - opt_aged = 1; + if (!opt_aged && (0 != opt_age_limit)) { + gettimeofday(&now, NULL); + if (last_selection_time.tv_sec + opt_age_limit < now.tv_sec) { + opt_aged = 1; + } } if (opt_aged) { diff --git a/src/headers/daemon.h b/src/headers/daemon.h index 24a1a97..a8db214 100644 --- a/src/headers/daemon.h +++ b/src/headers/daemon.h @@ -26,6 +26,7 @@ */ #include "gpm.h" /* Gpm_Event */ #include /* fd_set */ +#include /* timeval */ /************************************************************************* * Types / structures @@ -180,7 +181,7 @@ extern struct mouse_features mouse_table[3], extern Gpm_Type mice[]; extern Gpm_Type *repeated_type; -extern time_t last_selection_time; +extern struct timeval last_selection_time;