mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-02-16 17:24:23 +00:00
Fix unlikely lock file integer overflow
* src/filelock.c (within_one_second): Accept intmax_t first arg. Avoid undefined behavior on integer overflow. (current_lock_owner): Simplify based on within_one_second change.
This commit is contained in:
parent
8db72a8d4b
commit
cbacdca9e3
1 changed files with 4 additions and 4 deletions
|
|
@ -298,9 +298,10 @@ lock_file_1 (Lisp_Object lfname, bool force)
|
|||
/* Return true if times A and B are no more than one second apart. */
|
||||
|
||||
static bool
|
||||
within_one_second (time_t a, time_t b)
|
||||
within_one_second (intmax_t a, time_t b)
|
||||
{
|
||||
return (a - b >= -1 && a - b <= 1);
|
||||
intmax_t diff;
|
||||
return !ckd_sub (&diff, a, b) && -1 <= diff && diff <= 1;
|
||||
}
|
||||
|
||||
/* On systems lacking ELOOP, test for an errno value that shouldn't occur. */
|
||||
|
|
@ -469,8 +470,7 @@ current_lock_owner (lock_info_type *owner, Lisp_Object lfname)
|
|||
else if (VALID_PROCESS_ID (pid)
|
||||
&& (kill (pid, 0) >= 0 || errno == EPERM)
|
||||
&& (boot_time == 0
|
||||
|| (boot_time <= TYPE_MAXIMUM (time_t)
|
||||
&& within_one_second (boot_time, get_boot_sec ()))))
|
||||
|| within_one_second (boot_time, get_boot_sec ())))
|
||||
return ANOTHER_OWNS_IT;
|
||||
/* The owner process is dead or has a strange pid, so try to
|
||||
zap the lockfile. */
|
||||
|
|
|
|||
Loading…
Reference in a new issue