From: Rich Felker Date: Sat, 29 Jun 2013 04:02:38 +0000 (-0400) Subject: prevent shmget from allocating objects that overflow ptrdiff_t X-Git-Tag: v0.9.11~6 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=17aef0b41e3d7cb37c476cbe2df26fc444518a64;p=oweals%2Fmusl.git prevent shmget from allocating objects that overflow ptrdiff_t rather than returning an error, we have to increase the size argument so high that the kernel will have no choice but to fail. this is because POSIX only permits the EINVAL error for size errors when a new shared memory segment would be created; if it already exists, the size argument must be ignored. unfortunately Linux is non-conforming in this regard, but I want to keep the code correct in userspace anyway so that if/when Linux is fixed, the behavior applications see will be conforming. --- diff --git a/src/ipc/shmget.c b/src/ipc/shmget.c index 61fb11d9..b44f9d68 100644 --- a/src/ipc/shmget.c +++ b/src/ipc/shmget.c @@ -1,9 +1,11 @@ #include +#include #include "syscall.h" #include "ipc.h" int shmget(key_t key, size_t size, int flag) { + if (size > PTRDIFF_MAX) size = SIZE_MAX; #ifdef SYS_shmget return syscall(SYS_shmget, key, size, flag); #else