From 43060910874f46579fa190d9b5534508e4ea058e Mon Sep 17 00:00:00 2001 From: Po Lu Date: Wed, 23 Nov 2022 20:36:39 +0800 Subject: [PATCH] Improve last change to xterm.c * src/xfns.c (Fx_display_last_user_time): Reject overly large timestamps. * src/xterm.c (x_display_set_last_user_time, handle_one_xevent): New functions. --- src/xfns.c | 6 ++++-- src/xterm.c | 12 ++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/xfns.c b/src/xfns.c index 95092ce05f4..fa2c0751d90 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -9728,10 +9728,12 @@ selected frame's display. */) (Lisp_Object time_object, Lisp_Object terminal) { struct x_display_info *dpyinfo; - Time time; + uint32_t time; + /* time should be a 32-bit integer, regardless of what the size of + the X type `Time' is on this system. */ dpyinfo = check_x_display_info (terminal); - CONS_TO_INTEGER (time_object, Time, time); + CONS_TO_INTEGER (time_object, uint32_t, time); x_set_last_user_time_from_lisp (dpyinfo, time); return Qnil; diff --git a/src/xterm.c b/src/xterm.c index 732fbf462c9..cfd8c385d1d 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -7749,11 +7749,6 @@ x_display_set_last_user_time (struct x_display_info *dpyinfo, Time time, old_time = dpyinfo->last_user_time; #endif - /* Time can be sign extended if retrieved from a client message. - Make sure it is always 32 bits, or systems with 64-bit longs - will crash after 24 days of X server uptime. (bug#59480) */ - time &= X_ULONG_MAX; - #ifdef ENABLE_CHECKING eassert (time <= X_ULONG_MAX); #endif @@ -18626,7 +18621,12 @@ handle_one_xevent (struct x_display_info *dpyinfo, /* Set the provided time as the user time, which is required for SetInputFocus to work correctly after taking the input focus. */ - x_display_set_last_user_time (dpyinfo, event->xclient.data.l[1], + + /* Time can be sign extended if retrieved from a client message. + Make sure it is always 32 bits, or systems with 64-bit longs + will crash after 24 days of X server uptime. (bug#59480) */ + x_display_set_last_user_time (dpyinfo, (event->xclient.data.l[1] + & 0xffffffff), true, true); goto done; } -- 2.39.5