Skip to content

Commit 618e165

Browse files
aggargpaulbartell
authored andcommitted
Fix NULL pointer dereference in vPortGetHeapStats
When the heap is exhausted (no free block), start and end markers are the only blocks present in the free block list: +---------------+ +-----------> NULL | | | | V | + ----- + + ----- + | | | | | | | | | | | | + ----- + + ----- + xStart pxEnd The code block which traverses the list of free blocks to calculate heap stats used a do..while loop that moved past the end marker when the heap had no free block resulting in a NULL pointer dereference. This commit changes the do..while loop to while loop thereby ensuring that we never move past the end marker. This was reported here - #534 Signed-off-by: Gaurav Aggarwal <[email protected]>
1 parent dc9c034 commit 618e165

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

portable/MemMang/heap_4.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ void vPortGetHeapStats( HeapStats_t * pxHeapStats )
494494
* is initialised automatically when the first allocation is made. */
495495
if( pxBlock != NULL )
496496
{
497-
do
497+
while( pxBlock != pxEnd )
498498
{
499499
/* Increment the number of blocks and record the largest block seen
500500
* so far. */
@@ -513,7 +513,7 @@ void vPortGetHeapStats( HeapStats_t * pxHeapStats )
513513
/* Move to the next block in the chain until the last block is
514514
* reached. */
515515
pxBlock = pxBlock->pxNextFreeBlock;
516-
} while( pxBlock != pxEnd );
516+
}
517517
}
518518
}
519519
( void ) xTaskResumeAll();

portable/MemMang/heap_5.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ void vPortGetHeapStats( HeapStats_t * pxHeapStats )
544544
* is initialised automatically when the first allocation is made. */
545545
if( pxBlock != NULL )
546546
{
547-
do
547+
while( pxBlock != pxEnd )
548548
{
549549
/* Increment the number of blocks and record the largest block seen
550550
* so far. */
@@ -569,7 +569,7 @@ void vPortGetHeapStats( HeapStats_t * pxHeapStats )
569569
/* Move to the next block in the chain until the last block is
570570
* reached. */
571571
pxBlock = pxBlock->pxNextFreeBlock;
572-
} while( pxBlock != pxEnd );
572+
}
573573
}
574574
}
575575
( void ) xTaskResumeAll();

0 commit comments

Comments
 (0)