Skip to content

Commit 49f9130

Browse files
fxysunshinexiaoxiang781216
authored andcommitted
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 <fangxinyong@xiaomi.com>
1 parent b8b17f6 commit 49f9130

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎mm/mm_heap/mm_foreach.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ void mm_foreach(FAR struct mm_heap_s *heap, mm_node_handler_t handler,
9393

9494
handler(node, arg);
9595

96-
DEBUGASSERT(MM_PREVNODE_IS_ALLOC(node) ||
96+
DEBUGASSERT(prev == NULL ||
97+
MM_PREVNODE_IS_ALLOC(node) ||
9798
MM_SIZEOF_NODE(prev) == node->preceding);
9899
prev = node;
99100
}

0 commit comments

Comments
 (0)