disallow creation of objects larger than PTRDIFF_MAX via mmap
[musl] / src / mman / mmap.c
index e99271f..b56cff8 100644 (file)
@@ -1,6 +1,7 @@
 #include <unistd.h>
 #include <sys/mman.h>
 #include <errno.h>
 #include <unistd.h>
 #include <sys/mman.h>
 #include <errno.h>
+#include <stdint.h>
 #include <limits.h>
 #include "syscall.h"
 #include "libc.h"
 #include <limits.h>
 #include "syscall.h"
 #include "libc.h"
@@ -20,6 +21,10 @@ void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off)
                errno = EINVAL;
                return MAP_FAILED;
        }
                errno = EINVAL;
                return MAP_FAILED;
        }
+       if (len >= PTRDIFF_MAX) {
+               errno = ENOMEM;
+               return MAP_FAILED;
+       }
        if (flags & MAP_FIXED) __vm_lock(-1);
 #ifdef SYS_mmap2
        ret = (void *)syscall(SYS_mmap2, start, len, prot, flags, fd, off>>12);
        if (flags & MAP_FIXED) __vm_lock(-1);
 #ifdef SYS_mmap2
        ret = (void *)syscall(SYS_mmap2, start, len, prot, flags, fd, off>>12);