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
commit 49f913067533c40b5c457d1b77ecd8ff2f1bb588 Author: fangxinyong <[email protected]> AuthorDate: Fri Apr 24 11:38:19 2026 +0800 mm/mm_heap: fix null pointer dereference in mm_foreach On the first loop iteration prev is NULL. If the heap start node has a corrupted preceding field with MM_PREVFREE_BIT set, the short-circuit evaluation of the DEBUGASSERT falls through to MM_SIZEOF_NODE(prev) which dereferences NULL. Add a prev == NULL guard so the preceding-size consistency check is skipped for the first node, which has no predecessor. CID 1817303 (#1 of 1): Dereference null pointer (NULL_RETURNS) Signed-off-by: fangxinyong <[email protected]> --- mm/mm_heap/mm_foreach.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/mm_heap/mm_foreach.c b/mm/mm_heap/mm_foreach.c index b310170827a..22c0f992716 100644 --- a/mm/mm_heap/mm_foreach.c +++ b/mm/mm_heap/mm_foreach.c @@ -93,7 +93,8 @@ void mm_foreach(FAR struct mm_heap_s *heap, mm_node_handler_t handler, handler(node, arg); - DEBUGASSERT(MM_PREVNODE_IS_ALLOC(node) || + DEBUGASSERT(prev == NULL || + MM_PREVNODE_IS_ALLOC(node) || MM_SIZEOF_NODE(prev) == node->preceding); prev = node; }
