Skip to content

Commit 7eedbf7

Browse files
fix(freertos): Limit idle task name length copy operation
This commit limits the idle task name length copy operation to prevent Out-of-bounds memory access warnings from static code analyzers. Signed-off-by: Sudeep Mohanty <sudeep.mohanty@espressif.com>
1 parent 974351f commit 7eedbf7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tasks.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3521,11 +3521,16 @@ static BaseType_t prvCreateIdleTasks( void )
35213521
{
35223522
BaseType_t xReturn = pdPASS;
35233523
BaseType_t xCoreID;
3524-
char cIdleName[ configMAX_TASK_NAME_LEN ];
3524+
char cIdleName[ configMAX_TASK_NAME_LEN ] = { 0 };
35253525
TaskFunction_t pxIdleTaskFunction = NULL;
35263526
BaseType_t xIdleTaskNameIndex;
35273527

3528-
for( xIdleTaskNameIndex = ( BaseType_t ) 0; xIdleTaskNameIndex < ( BaseType_t ) configMAX_TASK_NAME_LEN; xIdleTaskNameIndex++ )
3528+
/* The length of the idle task name is limited to the minimum of the length
3529+
* of configIDLE_TASK_NAME and configMAX_TASK_NAME_LEN. */
3530+
BaseType_t cIdleNameLen = strlen( configIDLE_TASK_NAME );
3531+
BaseType_t xCopyLen = ( cIdleNameLen < configMAX_TASK_NAME_LEN ) ? cIdleNameLen : configMAX_TASK_NAME_LEN;
3532+
3533+
for( xIdleTaskNameIndex = ( BaseType_t ) 0; xIdleTaskNameIndex < xCopyLen; xIdleTaskNameIndex++ )
35293534
{
35303535
cIdleName[ xIdleTaskNameIndex ] = configIDLE_TASK_NAME[ xIdleTaskNameIndex ];
35313536

0 commit comments

Comments
 (0)