mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-19 21:11:57 -04:00
Add heap protector to allocted heap blocks (#1125)
When validate those allocated heap block structure, the canary is not used. Do xor with canary when allocating a new block. Signed-off-by: wangfei_chen <wangfei_chen@realsil.com.cn> Co-authored-by: wangfei_chen <wangfei_chen@realsil.com.cn>
This commit is contained in:
parent
e43553af1e
commit
18a168bcd2
|
@ -308,7 +308,7 @@ void * pvPortMalloc( size_t xWantedSize )
|
||||||
/* The block is being returned - it is allocated and owned
|
/* The block is being returned - it is allocated and owned
|
||||||
* by the application and has no "next" block. */
|
* by the application and has no "next" block. */
|
||||||
heapALLOCATE_BLOCK( pxBlock );
|
heapALLOCATE_BLOCK( pxBlock );
|
||||||
pxBlock->pxNextFreeBlock = NULL;
|
pxBlock->pxNextFreeBlock = heapPROTECT_BLOCK_POINTER( NULL );
|
||||||
xNumberOfSuccessfulAllocations++;
|
xNumberOfSuccessfulAllocations++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -367,11 +367,11 @@ void vPortFree( void * pv )
|
||||||
|
|
||||||
heapVALIDATE_BLOCK_POINTER( pxLink );
|
heapVALIDATE_BLOCK_POINTER( pxLink );
|
||||||
configASSERT( heapBLOCK_IS_ALLOCATED( pxLink ) != 0 );
|
configASSERT( heapBLOCK_IS_ALLOCATED( pxLink ) != 0 );
|
||||||
configASSERT( pxLink->pxNextFreeBlock == NULL );
|
configASSERT( pxLink->pxNextFreeBlock == heapPROTECT_BLOCK_POINTER( NULL ) );
|
||||||
|
|
||||||
if( heapBLOCK_IS_ALLOCATED( pxLink ) != 0 )
|
if( heapBLOCK_IS_ALLOCATED( pxLink ) != 0 )
|
||||||
{
|
{
|
||||||
if( pxLink->pxNextFreeBlock == NULL )
|
if( pxLink->pxNextFreeBlock == heapPROTECT_BLOCK_POINTER( NULL ) )
|
||||||
{
|
{
|
||||||
/* The block is being returned to the heap - it is no longer
|
/* The block is being returned to the heap - it is no longer
|
||||||
* allocated. */
|
* allocated. */
|
||||||
|
|
|
@ -336,7 +336,7 @@ void * pvPortMalloc( size_t xWantedSize )
|
||||||
/* The block is being returned - it is allocated and owned
|
/* The block is being returned - it is allocated and owned
|
||||||
* by the application and has no "next" block. */
|
* by the application and has no "next" block. */
|
||||||
heapALLOCATE_BLOCK( pxBlock );
|
heapALLOCATE_BLOCK( pxBlock );
|
||||||
pxBlock->pxNextFreeBlock = NULL;
|
pxBlock->pxNextFreeBlock = heapPROTECT_BLOCK_POINTER( NULL );
|
||||||
xNumberOfSuccessfulAllocations++;
|
xNumberOfSuccessfulAllocations++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -395,11 +395,11 @@ void vPortFree( void * pv )
|
||||||
|
|
||||||
heapVALIDATE_BLOCK_POINTER( pxLink );
|
heapVALIDATE_BLOCK_POINTER( pxLink );
|
||||||
configASSERT( heapBLOCK_IS_ALLOCATED( pxLink ) != 0 );
|
configASSERT( heapBLOCK_IS_ALLOCATED( pxLink ) != 0 );
|
||||||
configASSERT( pxLink->pxNextFreeBlock == NULL );
|
configASSERT( pxLink->pxNextFreeBlock == heapPROTECT_BLOCK_POINTER( NULL ) );
|
||||||
|
|
||||||
if( heapBLOCK_IS_ALLOCATED( pxLink ) != 0 )
|
if( heapBLOCK_IS_ALLOCATED( pxLink ) != 0 )
|
||||||
{
|
{
|
||||||
if( pxLink->pxNextFreeBlock == NULL )
|
if( pxLink->pxNextFreeBlock == heapPROTECT_BLOCK_POINTER( NULL ) )
|
||||||
{
|
{
|
||||||
/* The block is being returned to the heap - it is no longer
|
/* The block is being returned to the heap - it is no longer
|
||||||
* allocated. */
|
* allocated. */
|
||||||
|
|
Loading…
Reference in a new issue