Skip to content

Commit a7f3c1b

Browse files
Nuliu-Zjhedberg
authored andcommitted
ib: multi_heap: fix out-of-bounds array access
Add bounds check to prevent accessing heaps array with index=-1 when the address parameter is NULL or too small. Return NULL in such cases to match the API specification. Signed-off-by: Nulliu Z <[email protected]>
1 parent 5ce408b commit a7f3c1b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lib/heap/multi_heap.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@ const struct sys_multi_heap_rec *sys_multi_heap_get_heap(const struct sys_multi_
7575

7676
/* Now i stores the index of the heap after our target (even
7777
* if it's invalid and our target is the last!)
78-
* FIXME: return -ENOENT when a proper heap is not found
7978
*/
79+
if (i == 0) {
80+
return NULL;
81+
}
82+
8083
return &mheap->heaps[i-1];
8184
}
8285

0 commit comments

Comments
 (0)