This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch pr460
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/pr460 by this push:
     new 31a0a94  Prevents NuttX crashing if MM_REGIONS is too small.
31a0a94 is described below

commit 31a0a9469910abaa1e24e488106154c894065959
Author: Андрей Заболотный <zappare...@ya.ru>
AuthorDate: Thu Mar 5 19:15:18 2020 +0300

    Prevents NuttX crashing if MM_REGIONS is too small.
    
    Added a DEBUGASSERT and a runtime check so that mm_region will not
    overwrite critical heap data if user incorrectly defines MM_REGIONS.
---
 mm/mm_heap/mm_initialize.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/mm/mm_heap/mm_initialize.c b/mm/mm_heap/mm_initialize.c
index d979408..76ae030 100644
--- a/mm/mm_heap/mm_initialize.c
+++ b/mm/mm_heap/mm_initialize.c
@@ -75,6 +75,13 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void 
*heapstart,
   uintptr_t heapend;
 #if CONFIG_MM_REGIONS > 1
   int IDX = heap->mm_nregions;
+
+  /* Writing past CONFIG_MM_REGIONS would have catastrophic consequences */
+  DEBUGASSERT(IDX < CONFIG_MM_REGIONS);
+  if (IDX >= CONFIG_MM_REGIONS)
+    {
+      return;
+    }
 #else
 # define IDX 0
 #endif

Reply via email to