From ea3b40a321e751e016948087ef23ae7b9e8e0150 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 18 Jan 2023 23:15:58 -0500 Subject: fix integer overflow in WIFSTOPPED macro the result of the 0xffff mask with the exit status could have bit 15 set, in which case multiplying by 0x10001 overflows 32-bit signed int. making the multiply unsigned avoids the overflow. it also changes the sign extension behavior of the subsequent >> operation, but the affected bits are all unwanted anyway and all discarded by the cast to short. --- include/sys/wait.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/sys') diff --git a/include/sys/wait.h b/include/sys/wait.h index d4b1f2e1..8ced671b 100644 --- a/include/sys/wait.h +++ b/include/sys/wait.h @@ -50,7 +50,7 @@ pid_t wait4 (pid_t, int *, int, struct rusage *); #define WSTOPSIG(s) WEXITSTATUS(s) #define WCOREDUMP(s) ((s) & 0x80) #define WIFEXITED(s) (!WTERMSIG(s)) -#define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001)>>8) > 0x7f00) +#define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001U)>>8) > 0x7f00) #define WIFSIGNALED(s) (((s)&0xffff)-1U < 0xffu) #define WIFCONTINUED(s) ((s) == 0xffff) -- cgit v1.2.1