diff options
author | Rich Felker <dalias@aerifal.cx> | 2023-01-18 23:15:58 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2023-02-08 16:42:28 -0500 |
commit | ea3b40a321e751e016948087ef23ae7b9e8e0150 (patch) | |
tree | f4c353f26002191d8cfdb80e77aa1491773f4622 /include/stdlib.h | |
parent | f897461d4fe72bb71854a6d0662de83008caccb7 (diff) | |
download | musl-ea3b40a321e751e016948087ef23ae7b9e8e0150.zip musl-ea3b40a321e751e016948087ef23ae7b9e8e0150.tar.gz musl-ea3b40a321e751e016948087ef23ae7b9e8e0150.tar.bz2 |
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.
Diffstat (limited to 'include/stdlib.h')
-rw-r--r-- | include/stdlib.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/include/stdlib.h b/include/stdlib.h index b117a45..475190b 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -95,7 +95,7 @@ size_t __ctype_get_mb_cur_max(void); #define WTERMSIG(s) ((s) & 0x7f) #define WSTOPSIG(s) WEXITSTATUS(s) #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) int posix_memalign (void **, size_t, size_t); |