1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

Fix removal of file locks on MS-Windows 9X

A new Windows-specific function for validating process ID
is introduced that does TRT with possibly negative PID
values returned by 'getpid' on Windows 9X and also with
values larger than INT_MAX, since PID on Windows is
actually an unsigned 32-bit value.
* src/w32proc.c (w32_valid_process_id): New function.
* src/w32common.h (VALID_PROCESS_ID): Define for WINDOWSNT.
* src/filelock.c [WINDOWSNT]: Include w32common.h.  (Bug#71477)
This commit is contained in:
Eli Zaretskii 2024-06-13 10:24:21 +03:00
parent 94bcd7964b
commit 0007231a78
3 changed files with 17 additions and 1 deletions

View file

@ -47,6 +47,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#ifdef WINDOWSNT
#include <share.h>
#include <sys/socket.h> /* for fcntl */
#include "w32common.h"
#endif
#ifndef MSDOS
@ -353,7 +354,7 @@ integer_prefixed (char const *s)
/* Whether the integer P could identify an individual process. On most
platforms this simply checks for positive pid_t, but on some
Microsoft ports our headers #define it to to some other test. */
MS-Windows ports our headers #define it to to some other test. */
#ifndef VALID_PROCESS_ID
# define VALID_PROCESS_ID(p) (0 < (p) && (p) <= TYPE_MAXIMUM (pid_t))
#endif

View file

@ -53,6 +53,8 @@ extern void cache_system_info (void);
#ifdef WINDOWSNT
/* Return a static buffer with the MS-Windows version string. */
extern char * w32_version_string (void);
extern bool w32_valid_process_id (intmax_t);
# define VALID_PROCESS_ID(p) w32_valid_process_id(p)
#endif
typedef void (* VOIDFNPTR) (void);

View file

@ -2676,6 +2676,19 @@ count_children:
return nr;
}
/* This is called from filelock.c:current_lock_owner to validate a PID.
Return true if PID could identify a process on the current host,
false otherwise. */
bool
w32_valid_process_id (intmax_t id)
{
if (id == -1 || id == 0 /* always invalid */
|| id > UINT32_MAX /* PID is actually a DWORD */
|| id < INT32_MIN) /* Windows 9X can report negative PIDs */
return false;
return true;
}
/* Substitute for certain kill () operations */
static BOOL CALLBACK