From 1fd368d36024b2bbacde376b258b0d33648ff538 Mon Sep 17 00:00:00 2001 From: Georg Reinke Date: Tue, 28 Mar 2017 12:52:21 +0200 Subject: [PATCH] fix possible underflow in memory manager --- lib/memory.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/memory.c b/lib/memory.c index 1e7f10e65..1cde4c9ae 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -120,6 +120,9 @@ void* memory_managed_alloc(struct memtype *m, size_t len, size_t alignment) uintptr_t gap = 0; if (rem != 0) { gap = alignment - rem; + if (gap > avail) + // next aligned address isn't in this block anymore + continue; cptr += gap; avail -= gap; }