Skip to content

Commit

Permalink
Fix size alignment in the integer overflow issue (#839)
Browse files Browse the repository at this point in the history
  • Loading branch information
kar-rahul-aws authored Oct 19, 2023
1 parent 2207715 commit b32aafe
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions portable/Common/mpu_wrappers_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@
#define CONVERT_TO_INTERNAL_INDEX( lIndex ) ( ( lIndex ) - INDEX_OFFSET )

/**
* @brief Max value that fits in a size_t type.
* @brief Max value that fits in a uint32_t type.
*/
#define mpuSIZE_MAX ( ~( ( size_t ) 0 ) )
#define mpuUINT32_MAX ( ~( ( uint32_t ) 0 ) )

/**
* @brief Check if multiplying a and b will result in overflow.
*/
#define mpuMULTIPLY_WILL_OVERFLOW( a, b ) ( ( ( a ) > 0 ) && ( ( b ) > ( mpuSIZE_MAX / ( a ) ) ) )
#define mpuMULTIPLY_UINT32_WILL_OVERFLOW( a, b ) ( ( ( a ) > 0 ) && ( ( b ) > ( mpuUINT32_MAX / ( a ) ) ) )

/**
* @brief Get the index of a free slot in the kernel object pool.
Expand Down Expand Up @@ -1048,11 +1048,13 @@
UBaseType_t uxReturn = 0;
UBaseType_t xIsTaskStatusArrayWriteable = pdFALSE;
UBaseType_t xIsTotalRunTimeWriteable = pdFALSE;
uint32_t ulArraySize = ( uint32_t ) uxArraySize;
uint32_t ulTaskStatusSize = ( uint32_t ) sizeof( TaskStatus_t );

if( mpuMULTIPLY_WILL_OVERFLOW( sizeof( TaskStatus_t ), uxArraySize ) == 0 )
if( mpuMULTIPLY_UINT32_WILL_OVERFLOW( ulTaskStatusSize, ulArraySize ) == 0 )
{
xIsTaskStatusArrayWriteable = xPortIsAuthorizedToAccessBuffer( pxTaskStatusArray,
sizeof( TaskStatus_t ) * uxArraySize,
ulTaskStatusSize * ulArraySize,
tskMPU_WRITE_PERMISSION );

if( pulTotalRunTime != NULL )
Expand All @@ -1065,7 +1067,7 @@
if( ( xIsTaskStatusArrayWriteable == pdTRUE ) &&
( ( pulTotalRunTime == NULL ) || ( xIsTotalRunTimeWriteable == pdTRUE ) ) )
{
uxReturn = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, pulTotalRunTime );
uxReturn = uxTaskGetSystemState( pxTaskStatusArray, ( UBaseType_t ) ulArraySize, pulTotalRunTime );
}
}

Expand Down

0 comments on commit b32aafe

Please sign in to comment.