From f866e270811e40ec0b8faa3e22d4146acbafff94 Mon Sep 17 00:00:00 2001 From: Henrik Stickann <4376396-Mithradir@users.noreply.gitlab.com> Date: Fri, 20 Jan 2023 14:12:40 +0100 Subject: [PATCH] Implement robust task name printing --- src/debug/stack_overflow.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/debug/stack_overflow.cpp b/src/debug/stack_overflow.cpp index 06cf2a7..158c454 100644 --- a/src/debug/stack_overflow.cpp +++ b/src/debug/stack_overflow.cpp @@ -8,14 +8,25 @@ #include -extern "C" void vApplicationStackOverflowHook(xTaskHandle xTask, signed char *pcTaskName) +extern "C" void vApplicationStackOverflowHook(xTaskHandle xTask, char * pcTaskName) { - // TODO Handle corrupted parameters - // * check pcTaskName is cstring (look for \0 within ? bytes) STA_DEBUG_PRINT("Stack overflow detected in task "); if (pcTaskName) { - STA_DEBUG_PRINTLN(pcTaskName); + // Manually calculate string length + // Limited to configMAX_TASK_NAME_LEN to avoid reading + // garbage values in case TCB has been corrupted + size_t len = 0; + while (len < configMAX_TASK_NAME_LEN) + { + if (pcTaskName[len] == '\0') + { + break; + } + ++len; + } + + STA_DEBUG_PRINTLN(pcTaskName, len); } STA_HALT(); }