mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] prevent allocs than PTRDIFF_MAX via mremap
@ 2015-10-31  9:14 Daniel Micay
  2015-10-31  9:20 ` Daniel Micay
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Micay @ 2015-10-31  9:14 UTC (permalink / raw)
  To: musl; +Cc: Daniel Micay

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.6.2



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-11-02 21:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-31  9:14 [PATCH] prevent allocs than PTRDIFF_MAX via mremap Daniel Micay
2015-10-31  9:20 ` Daniel Micay
2015-10-31 20:30   ` Rich Felker
2015-11-02 21:46     ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).