summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2015-10-31 05:14:45 -0400
committerRich Felker <dalias@aerifal.cx>2015-11-02 16:30:25 -0500
commitf9ecb6bfa1dc9f93a10dad97a158e6b8334c586c (patch)
treeda35380f907cb59e6835eaa733d6643d65715edf /src
parent36e8b6a28be5d4ffad966386b1e1c0d0dc6ca11a (diff)
downloadmusl-f9ecb6bfa1dc9f93a10dad97a158e6b8334c586c.tar.gz
musl-f9ecb6bfa1dc9f93a10dad97a158e6b8334c586c.tar.bz2
musl-f9ecb6bfa1dc9f93a10dad97a158e6b8334c586c.tar.xz
musl-f9ecb6bfa1dc9f93a10dad97a158e6b8334c586c.zip
prevent allocs than PTRDIFF_MAX via mremap
It's quite feasible for this to happen via MREMAP_MAYMOVE.
Diffstat (limited to 'src')
-rw-r--r--src/mman/mremap.c9
1 files changed, 8 insertions, 1 deletions
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 <unistd.h>
#include <sys/mman.h>
+#include <errno.h>
+#include <stdint.h>
#include <stdarg.h>
#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);