Skip to content

Commit b32aafe

Browse files
Fix size alignment in the integer overflow issue (#839)
1 parent 2207715 commit b32aafe

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

portable/Common/mpu_wrappers_v2.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@
113113
#define CONVERT_TO_INTERNAL_INDEX( lIndex ) ( ( lIndex ) - INDEX_OFFSET )
114114

115115
/**
116-
* @brief Max value that fits in a size_t type.
116+
* @brief Max value that fits in a uint32_t type.
117117
*/
118-
#define mpuSIZE_MAX ( ~( ( size_t ) 0 ) )
118+
#define mpuUINT32_MAX ( ~( ( uint32_t ) 0 ) )
119119

120120
/**
121121
* @brief Check if multiplying a and b will result in overflow.
122122
*/
123-
#define mpuMULTIPLY_WILL_OVERFLOW( a, b ) ( ( ( a ) > 0 ) && ( ( b ) > ( mpuSIZE_MAX / ( a ) ) ) )
123+
#define mpuMULTIPLY_UINT32_WILL_OVERFLOW( a, b ) ( ( ( a ) > 0 ) && ( ( b ) > ( mpuUINT32_MAX / ( a ) ) ) )
124124

125125
/**
126126
* @brief Get the index of a free slot in the kernel object pool.
@@ -1048,11 +1048,13 @@
10481048
UBaseType_t uxReturn = 0;
10491049
UBaseType_t xIsTaskStatusArrayWriteable = pdFALSE;
10501050
UBaseType_t xIsTotalRunTimeWriteable = pdFALSE;
1051+
uint32_t ulArraySize = ( uint32_t ) uxArraySize;
1052+
uint32_t ulTaskStatusSize = ( uint32_t ) sizeof( TaskStatus_t );
10511053

1052-
if( mpuMULTIPLY_WILL_OVERFLOW( sizeof( TaskStatus_t ), uxArraySize ) == 0 )
1054+
if( mpuMULTIPLY_UINT32_WILL_OVERFLOW( ulTaskStatusSize, ulArraySize ) == 0 )
10531055
{
10541056
xIsTaskStatusArrayWriteable = xPortIsAuthorizedToAccessBuffer( pxTaskStatusArray,
1055-
sizeof( TaskStatus_t ) * uxArraySize,
1057+
ulTaskStatusSize * ulArraySize,
10561058
tskMPU_WRITE_PERMISSION );
10571059

10581060
if( pulTotalRunTime != NULL )
@@ -1065,7 +1067,7 @@
10651067
if( ( xIsTaskStatusArrayWriteable == pdTRUE ) &&
10661068
( ( pulTotalRunTime == NULL ) || ( xIsTotalRunTimeWriteable == pdTRUE ) ) )
10671069
{
1068-
uxReturn = uxTaskGetSystemState( pxTaskStatusArray, uxArraySize, pulTotalRunTime );
1070+
uxReturn = uxTaskGetSystemState( pxTaskStatusArray, ( UBaseType_t ) ulArraySize, pulTotalRunTime );
10691071
}
10701072
}
10711073

0 commit comments

Comments
 (0)