Skip to content

Commit

Permalink
Sanitize log_size before using it.
Browse files Browse the repository at this point in the history
For some reason log_size became a huge value (probably a pointer?) in my settings.
Better sanitize it to sane values before using that value. Fixes a crash while loading settings.
  • Loading branch information
jackburton79 committed Dec 6, 2024
1 parent 443c804 commit 9190d18
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/helpers/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ Logger::SetDestination(int destination)
void
Logger::LogFormat(const char* fmtString, ...)
{
const int32 logArraySize = (int32)gCFG["log_size"];
int32 logArraySize = (int32)gCFG["log_size"];
// Sanitize
if (logArraySize < 1024)
logArraySize = 1024;
else if (logArraySize > 4096)
logArraySize = 4096;

#if __clang__
char* logString = new char[logArraySize];
#else
Expand All @@ -52,7 +58,12 @@ Logger::LogFormat(const char* fmtString, ...)
void
Logger::LogFormat(log_level level, const char* fmtString, ...)
{
const int32 logArraySize = (int32)gCFG["log_size"];
int32 logArraySize = (int32)gCFG["log_size"];
// Sanitize
if (logArraySize < 1024)
logArraySize = 1024;
else if (logArraySize > 4096)
logArraySize = 4096;

// Prepend the log level
#if __clang__
Expand Down

0 comments on commit 9190d18

Please sign in to comment.