From a7f0e915390d543824021f192368c35155ff0dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Wed, 6 Jan 2021 11:39:24 +0100 Subject: [PATCH] cppcheckexecutor.cpp: fixed stack-use-after-scope reported by ASAN (#3018) --- cli/cppcheckexecutor.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 711d7b52d..e34feb90b 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -278,6 +278,7 @@ static void print_stacktrace(FILE* output, bool demangling, int maxdepth, bool l char **symbolStringList = backtrace_symbols(callstackArray, currentdepth); if (symbolStringList) { fputs("Callstack:\n", output); + char demangle_buffer[2048]= {0}; for (int i = offset; i < maxdepth; ++i) { const char * const symbolString = symbolStringList[i]; char * realnameString = nullptr; @@ -292,12 +293,11 @@ static void print_stacktrace(FILE* output, bool demangling, int maxdepth, bool l if (plus && (plus>(firstBracketName+1))) { char input_buffer[1024]= {0}; strncpy(input_buffer, firstBracketName+1, plus-firstBracketName-1); - char output_buffer[2048]= {0}; - size_t length = getArrayLength(output_buffer); + size_t length = getArrayLength(demangle_buffer); int status=0; // We're violating the specification - passing stack address instead of malloc'ed heap. // Benefit is that no further heap is required, while there is sufficient stack... - realnameString = abi::__cxa_demangle(input_buffer, output_buffer, &length, &status); // non-NULL on success + realnameString = abi::__cxa_demangle(input_buffer, demangle_buffer, &length, &status); // non-NULL on success } } const int ordinal=i-offset;