fix condition where the Log and ActivityLog would overflow the character buffer by no properly calculating the length of the va_args string (this should resolve buffer overflow terminations on GCC 13+);

pull/55/head
Bryan Biedenkapp 2 years ago
parent 7f5387498b
commit 36099367c8

@ -35,7 +35,7 @@
#define EOL "\r\n"
const uint32_t LOG_BUFFER_LEN = 16384U;
const uint32_t LOG_BUFFER_LEN = 4096U;
// ---------------------------------------------------------------------------
// Global Variables
@ -216,11 +216,14 @@ void Log(uint32_t level, const char *module, const char* fmt, ...)
}
}
va_list vl;
va_list vl, vl_len;
va_start(vl, fmt);
va_copy(vl_len, vl);
::vsnprintf(buffer + ::strlen(buffer), LOG_BUFFER_LEN - 1U, fmt, vl);
size_t len = ::vsnprintf(nullptr, 0U, fmt, vl_len);
::vsnprintf(buffer + ::strlen(buffer), len + 1U, fmt, vl);
va_end(vl_len);
va_end(vl);
if (m_outStream && g_logDisplayLevel == 0U) {

@ -119,11 +119,14 @@ void ActivityLog(const char* msg, ...)
char buffer[ACT_LOG_BUFFER_LEN];
va_list vl;
va_list vl, vl_len;
va_start(vl, msg);
va_copy(vl_len, vl);
::vsnprintf(buffer, ACT_LOG_BUFFER_LEN - 1U, msg, vl);
size_t len = ::vsnprintf(nullptr, 0U, msg, vl_len);
::vsnprintf(buffer, len + 1U, msg, vl);
va_end(vl_len);
va_end(vl);
bool ret = ::ActivityLogOpen();

@ -138,11 +138,14 @@ void ActivityLog(const char *mode, const bool sourceRf, const char* msg, ...)
::sprintf(buffer, "A: %04d-%02d-%02d %02d:%02d:%02d.%03lu %s %s ", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, now.tv_usec / 1000U, mode, (sourceRf) ? "RF" : "Net");
}
va_list vl;
va_list vl, vl_len;
va_start(vl, msg);
va_copy(vl_len, vl);
::vsnprintf(buffer + ::strlen(buffer), ACT_LOG_BUFFER_LEN - 1U, msg, vl);
size_t len = ::vsnprintf(nullptr, 0U, msg, vl_len);
::vsnprintf(buffer + ::strlen(buffer), len + 1U, msg, vl);
va_end(vl_len);
va_end(vl);
bool ret = ::ActivityLogOpen();

Loading…
Cancel
Save

Powered by TurnKey Linux.