From 95dc647c3cf55d9a4a9edc4453c696b730b43d77 Mon Sep 17 00:00:00 2001 From: Oki Minabe Date: Sat, 1 Feb 2020 17:45:08 +0900 Subject: [PATCH] mm/umm_heap/: Handle size zero in umm_malloc.c and umm_realloc.c, which causes a system freeze in kernel mode. --- mm/umm_heap/umm_malloc.c | 5 +++++ mm/umm_heap/umm_realloc.c | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/mm/umm_heap/umm_malloc.c b/mm/umm_heap/umm_malloc.c index 7f38ac3e3c..ea2f13eeaf 100644 --- a/mm/umm_heap/umm_malloc.c +++ b/mm/umm_heap/umm_malloc.c @@ -70,6 +70,11 @@ FAR void *malloc(size_t size) FAR void *brkaddr; FAR void *mem; + if (size < 1) + { + return NULL; + } + /* Loop until we successfully allocate the memory or until an error * occurs. If we fail to allocate memory on the first pass, then call * sbrk to extend the heap by one page. This may require several diff --git a/mm/umm_heap/umm_realloc.c b/mm/umm_heap/umm_realloc.c index 5538bf5414..0a27df49c9 100644 --- a/mm/umm_heap/umm_realloc.c +++ b/mm/umm_heap/umm_realloc.c @@ -71,6 +71,12 @@ FAR void *realloc(FAR void *oldmem, size_t size) FAR void *brkaddr; FAR void *mem; + if (size < 1) + { + mm_free(USR_HEAP, oldmem); + return NULL; + } + /* Loop until we successfully allocate the memory or until an error * occurs. If we fail to allocate memory on the first pass, then call * sbrk to extend the heap by one page. This may require several