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

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new b50804c5f17 sched/coredump: fix NULL access when adding the first 
memory region
b50804c5f17 is described below

commit b50804c5f17a62d8db7ce55250abf4de848efc96
Author: yangao1 <[email protected]>
AuthorDate: Thu Apr 17 20:10:01 2025 +0800

    sched/coredump: fix NULL access when adding the first memory region
    
    coredump_add_memory_region() starts with count = 1 for the end marker,
    so when no region has been registered yet (g_regions is NULL, e.g.
    without CONFIG_BOARD_MEMORY_RANGE) the memcpy() of the old table read
    one struct memory_region_s from address 0.  Only copy the old table
    when there is one.
    
    Signed-off-by: yangao1 <[email protected]>
---
 sched/misc/coredump.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sched/misc/coredump.c b/sched/misc/coredump.c
index 90ac09ef18b..eb9318e038c 100644
--- a/sched/misc/coredump.c
+++ b/sched/misc/coredump.c
@@ -928,7 +928,10 @@ int coredump_add_memory_region(FAR const void *ptr, size_t 
size,
       return -ENOMEM;
     }
 
-  memcpy(region, g_regions, sizeof(struct memory_region_s) * count);
+  if (g_regions != NULL)
+    {
+      memcpy(region, g_regions, sizeof(struct memory_region_s) * count);
+    }
 
   if (g_regions != NULL
 #ifdef CONFIG_BOARD_MEMORY_RANGE

Reply via email to