From 0a2c96cfcc52e23d30070e2ab96f8248af56fe93 Mon Sep 17 00:00:00 2001 From: Jakub Jermar Date: Sun, 29 Sep 2019 15:57:17 +0200 Subject: [PATCH] Check for unsigned wrap-around in malloc --- kernel/generic/src/mm/malloc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/generic/src/mm/malloc.c b/kernel/generic/src/mm/malloc.c index 442ddf84e..e42e95812 100644 --- a/kernel/generic/src/mm/malloc.c +++ b/kernel/generic/src/mm/malloc.c @@ -186,6 +186,9 @@ static const size_t _offset = ALIGN_UP(sizeof(size_t), alignof(max_align_t)); void *malloc(size_t size) { + if (size + _offset < size) + return NULL; + void *obj = mem_alloc(alignof(max_align_t), size + _offset) + _offset; /* Remember the allocation size just before the object. */ -- 2.11.4.GIT