From: Daniel Micay Date: Sat, 31 Oct 2015 09:14:45 +0000 (-0400) Subject: prevent allocs than PTRDIFF_MAX via mremap X-Git-Tag: v1.1.13~142 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=f9ecb6bfa1dc9f93a10dad97a158e6b8334c586c;p=oweals%2Fmusl.git prevent allocs than PTRDIFF_MAX via mremap It's quite feasible for this to happen via MREMAP_MAYMOVE. --- diff --git a/src/mman/mremap.c b/src/mman/mremap.c index 596c45fb..1096ace1 100644 --- a/src/mman/mremap.c +++ b/src/mman/mremap.c @@ -1,5 +1,7 @@ #include #include +#include +#include #include #include "syscall.h" #include "libc.h" @@ -8,7 +10,12 @@ void *__mremap(void *old_addr, size_t old_len, size_t new_len, int flags, ...) { va_list ap; void *new_addr; - + + if (new_len >= PTRDIFF_MAX) { + errno = ENOMEM; + return MAP_FAILED; + } + va_start(ap, flags); new_addr = va_arg(ap, void *); va_end(ap);