From 1bb7de1dd91110b6b399c13dadb9109fc8f073fe Mon Sep 17 00:00:00 2001 From: baraclese <1628879+baraclese@users.noreply.github.com> Date: Tue, 5 Mar 2024 18:57:11 +0100 Subject: [PATCH] fix segfault in CMultiLogger vsprintf may change its va_list argument so repeatedly calling it with the same va_list arg is undefined behavior. Fix this by creating a copy of the va_list argument before each vsprintf call. --- Src/OSD/Logger.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Src/OSD/Logger.cpp b/Src/OSD/Logger.cpp index ad7aa48..4e63e6e 100644 --- a/Src/OSD/Logger.cpp +++ b/Src/OSD/Logger.cpp @@ -168,7 +168,10 @@ void CMultiLogger::DebugLog(const char *fmt, va_list vl) { for (auto &logger: m_loggers) { - logger->DebugLog(fmt, vl); + va_list vl_tmp; + va_copy(vl_tmp, vl); + logger->DebugLog(fmt, vl_tmp); + va_end(vl_tmp); } } @@ -176,7 +179,10 @@ void CMultiLogger::InfoLog(const char *fmt, va_list vl) { for (auto &logger: m_loggers) { - logger->InfoLog(fmt, vl); + va_list vl_tmp; + va_copy(vl_tmp, vl); + logger->InfoLog(fmt, vl_tmp); + va_end(vl_tmp); } } @@ -184,7 +190,10 @@ void CMultiLogger::ErrorLog(const char *fmt, va_list vl) { for (auto &logger: m_loggers) { - logger->ErrorLog(fmt, vl); + va_list vl_tmp; + va_copy(vl_tmp, vl); + logger->ErrorLog(fmt, vl_tmp); + va_end(vl_tmp); } } @@ -391,4 +400,4 @@ void CSystemLogger::ErrorLog(const char *fmt, va_list vl) CSystemLogger::CSystemLogger(CLogger::LogLevel level) : m_logLevel(level) { -} \ No newline at end of file +}