aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/0006-prevent-allocs-than-PTRDIFF_MAX-via-mremap.patch
blob: d373ac9114085fc98a5b30303955d8721ad0be17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
From f9ecb6bfa1dc9f93a10dad97a158e6b8334c586c Mon Sep 17 00:00:00 2001
From: Daniel Micay <danielmicay@gmail.com>
Date: Sat, 31 Oct 2015 05:14:45 -0400
Subject: [PATCH] prevent allocs than PTRDIFF_MAX via mremap

It's quite feasible for this to happen via MREMAP_MAYMOVE.
---
 src/mman/mremap.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/mman/mremap.c b/src/mman/mremap.c
index 596c45f..1096ace 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);
-- 
2.7.0