diff options
| author | Paul Eggert | 2024-08-15 11:29:16 -0700 |
|---|---|---|
| committer | Paul Eggert | 2024-08-15 13:31:31 -0700 |
| commit | cbacdca9e3f6dcf9b88704391f06daf7301608b0 (patch) | |
| tree | b2baf743b281ad88e68507523e71a82efd74febd /src | |
| parent | 8db72a8d4b77ccdbb68f7361a52d7f2ebe78b656 (diff) | |
| download | emacs-cbacdca9e3f6dcf9b88704391f06daf7301608b0.tar.gz emacs-cbacdca9e3f6dcf9b88704391f06daf7301608b0.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/filelock.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/filelock.c b/src/filelock.c index 69bd0322d4c..55ab15feb8d 100644 --- a/src/filelock.c +++ b/src/filelock.c | |||
| @@ -298,9 +298,10 @@ lock_file_1 (Lisp_Object lfname, bool force) | |||
| 298 | /* Return true if times A and B are no more than one second apart. */ | 298 | /* Return true if times A and B are no more than one second apart. */ |
| 299 | 299 | ||
| 300 | static bool | 300 | static bool |
| 301 | within_one_second (time_t a, time_t b) | 301 | within_one_second (intmax_t a, time_t b) |
| 302 | { | 302 | { |
| 303 | return (a - b >= -1 && a - b <= 1); | 303 | intmax_t diff; |
| 304 | return !ckd_sub (&diff, a, b) && -1 <= diff && diff <= 1; | ||
| 304 | } | 305 | } |
| 305 | 306 | ||
| 306 | /* On systems lacking ELOOP, test for an errno value that shouldn't occur. */ | 307 | /* 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) | |||
| 469 | else if (VALID_PROCESS_ID (pid) | 470 | else if (VALID_PROCESS_ID (pid) |
| 470 | && (kill (pid, 0) >= 0 || errno == EPERM) | 471 | && (kill (pid, 0) >= 0 || errno == EPERM) |
| 471 | && (boot_time == 0 | 472 | && (boot_time == 0 |
| 472 | || (boot_time <= TYPE_MAXIMUM (time_t) | 473 | || within_one_second (boot_time, get_boot_sec ()))) |
| 473 | && within_one_second (boot_time, get_boot_sec ())))) | ||
| 474 | return ANOTHER_OWNS_IT; | 474 | return ANOTHER_OWNS_IT; |
| 475 | /* The owner process is dead or has a strange pid, so try to | 475 | /* The owner process is dead or has a strange pid, so try to |
| 476 | zap the lockfile. */ | 476 | zap the lockfile. */ |