From fdaaa9e3d6924e74ad09b2aac21fc89bb4ca21b8 Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Fri, 6 Dec 2024 10:41:54 +0530 Subject: [PATCH] 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 --- tasks.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tasks.c b/tasks.c index 22e11f0fb21..e0a027e5906 100644 --- a/tasks.c +++ b/tasks.c @@ -3521,11 +3521,16 @@ static BaseType_t prvCreateIdleTasks( void ) { BaseType_t xReturn = pdPASS; BaseType_t xCoreID; - char cIdleName[ configMAX_TASK_NAME_LEN ]; + char cIdleName[ configMAX_TASK_NAME_LEN ] = {0}; TaskFunction_t pxIdleTaskFunction = NULL; BaseType_t xIdleTaskNameIndex; - for( xIdleTaskNameIndex = ( BaseType_t ) 0; xIdleTaskNameIndex < ( BaseType_t ) configMAX_TASK_NAME_LEN; xIdleTaskNameIndex++ ) + /* The length of the idle task name is limited to the minimum of the length + * of configIDLE_TASK_NAME and configMAX_TASK_NAME_LEN. */ + BaseType_t cIdleNameLen = strlen( configIDLE_TASK_NAME ); + BaseType_t xCopyLen = ( cIdleNameLen < configMAX_TASK_NAME_LEN ) ? cIdleNameLen : configMAX_TASK_NAME_LEN; + + for( xIdleTaskNameIndex = ( BaseType_t ) 0; xIdleTaskNameIndex < xCopyLen; xIdleTaskNameIndex++ ) { cIdleName[ xIdleTaskNameIndex ] = configIDLE_TASK_NAME[ xIdleTaskNameIndex ];