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 )
/**
* @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.
*
@ -1035,10 +1045,12 @@
UBaseType_t uxArraySize,
configRUN_TIME_COUNTER_TYPE * pulTotalRunTime ) /* PRIVILEGED_FUNCTION */
{
UBaseType_t uxReturn = pdFALSE;
UBaseType_t uxReturn = 0;
UBaseType_t xIsTaskStatusArrayWriteable = pdFALSE;
UBaseType_t xIsTotalRunTimeWriteable = pdFALSE;
if( mpuMULTIPLY_WILL_OVERFLOW( sizeof( TaskStatus_t ), uxArraySize ) == 0 )
{
xIsTaskStatusArrayWriteable = xPortIsAuthorizedToAccessBuffer( pxTaskStatusArray,
sizeof( TaskStatus_t ) * uxArraySize,
tskMPU_WRITE_PERMISSION );
@ -1055,6 +1067,7 @@
{
uxReturn = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, pulTotalRunTime );
}
}
return uxReturn;
}

Loading…
Cancel
Save