Fix possible integer overflow (#836)

* Fix possible integer overflow

---------

Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com>
pull/838/head
Gaurav-Aggarwal-AWS 1 year ago committed by GitHub
parent 59ba98b2e3
commit 4ada1d7d5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -112,6 +112,16 @@
*/ */
#define CONVERT_TO_INTERNAL_INDEX( lIndex ) ( ( lIndex ) - INDEX_OFFSET ) #define CONVERT_TO_INTERNAL_INDEX( lIndex ) ( ( lIndex ) - INDEX_OFFSET )
/**
* @brief Max value that fits in a size_t type.
*/
#define mpuSIZE_MAX ( ~( ( size_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 ) ) ) )
/** /**
* @brief Get the index of a free slot in the kernel object pool. * @brief Get the index of a free slot in the kernel object pool.
* *
@ -1035,25 +1045,28 @@
UBaseType_t uxArraySize, UBaseType_t uxArraySize,
configRUN_TIME_COUNTER_TYPE * pulTotalRunTime ) /* PRIVILEGED_FUNCTION */ configRUN_TIME_COUNTER_TYPE * pulTotalRunTime ) /* PRIVILEGED_FUNCTION */
{ {
UBaseType_t uxReturn = pdFALSE; UBaseType_t uxReturn = 0;
UBaseType_t xIsTaskStatusArrayWriteable = pdFALSE; UBaseType_t xIsTaskStatusArrayWriteable = pdFALSE;
UBaseType_t xIsTotalRunTimeWriteable = pdFALSE; UBaseType_t xIsTotalRunTimeWriteable = pdFALSE;
xIsTaskStatusArrayWriteable = xPortIsAuthorizedToAccessBuffer( pxTaskStatusArray, if( mpuMULTIPLY_WILL_OVERFLOW( sizeof( TaskStatus_t ), uxArraySize ) == 0 )
sizeof( TaskStatus_t ) * uxArraySize,
tskMPU_WRITE_PERMISSION );
if( pulTotalRunTime != NULL )
{ {
xIsTotalRunTimeWriteable = xPortIsAuthorizedToAccessBuffer( pulTotalRunTime, xIsTaskStatusArrayWriteable = xPortIsAuthorizedToAccessBuffer( pxTaskStatusArray,
sizeof( configRUN_TIME_COUNTER_TYPE ), sizeof( TaskStatus_t ) * uxArraySize,
tskMPU_WRITE_PERMISSION ); tskMPU_WRITE_PERMISSION );
}
if( ( xIsTaskStatusArrayWriteable == pdTRUE ) && if( pulTotalRunTime != NULL )
( ( pulTotalRunTime == NULL ) || ( xIsTotalRunTimeWriteable == pdTRUE ) ) ) {
{ xIsTotalRunTimeWriteable = xPortIsAuthorizedToAccessBuffer( pulTotalRunTime,
uxReturn = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, pulTotalRunTime ); sizeof( configRUN_TIME_COUNTER_TYPE ),
tskMPU_WRITE_PERMISSION );
}
if( ( xIsTaskStatusArrayWriteable == pdTRUE ) &&
( ( pulTotalRunTime == NULL ) || ( xIsTotalRunTimeWriteable == pdTRUE ) ) )
{
uxReturn = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, pulTotalRunTime );
}
} }
return uxReturn; return uxReturn;

Loading…
Cancel
Save