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)
(cherry picked from commit
0007231a7805abce945349c7c9c75b45155bda5c)
#ifdef WINDOWSNT
#include <share.h>
#include <sys/socket.h> /* for fcntl */
+#include "w32common.h"
#endif
#ifndef MSDOS
/* 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
#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);
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