From 54fdeb1ad5ca51b85833806173f3eed713fa369d Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 8 Feb 2023 13:14:41 -0500 Subject: [PATCH] Fix stack dynamic buffer overflow in the logging lib --- src/blt/std/logging.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/blt/std/logging.cpp b/src/blt/std/logging.cpp index 03dc970..ef30261 100644 --- a/src/blt/std/logging.cpp +++ b/src/blt/std/logging.cpp @@ -61,8 +61,9 @@ namespace blt::logging { }; void applyFormatting(const std::string& format, std::string& output, va_list& args){ - char formattedChars[format.length()]; - vsprintf(formattedChars, format.c_str(), args); + const char* fmt_c_str = format.c_str(); + char formattedChars[1+std::vsnprintf(nullptr, 0, fmt_c_str, args)]; + vsprintf(formattedChars, fmt_c_str, args); output = std::string(formattedChars); }