Add log buffer max size check

This commit is contained in:
Theo Arends 2021-05-31 18:34:51 +02:00
parent d8664da889
commit d01f577782
1 changed files with 4 additions and 1 deletions

View File

@ -2307,6 +2307,9 @@ void AddLogData(uint32_t loglevel, const char* log_data) {
Serial.printf("%s%s\r\n", mxtime, log_data);
}
uint32_t log_data_len = strlen(log_data) + strlen(mxtime) + 4; // 4 = log_buffer_pointer + '\1' + '\0'
if (log_data_len > LOG_BUFFER_SIZE) { return; } // log_data too big for buffer - discard logging
uint32_t highest_loglevel = Settings.weblog_level;
if (Settings.mqttlog_level > highest_loglevel) { highest_loglevel = Settings.mqttlog_level; }
if (TasmotaGlobal.syslog_level > highest_loglevel) { highest_loglevel = TasmotaGlobal.syslog_level; }
@ -2322,7 +2325,7 @@ void AddLogData(uint32_t loglevel, const char* log_data) {
TasmotaGlobal.log_buffer_pointer++; // Index 0 is not allowed as it is the end of char string
}
while (TasmotaGlobal.log_buffer_pointer == TasmotaGlobal.log_buffer[0] || // If log already holds the next index, remove it
strlen(TasmotaGlobal.log_buffer) + strlen(log_data) + strlen(mxtime) + 4 > LOG_BUFFER_SIZE) // 4 = log_buffer_pointer + '\1' + '\0'
strlen(TasmotaGlobal.log_buffer) + log_data_len > LOG_BUFFER_SIZE)
{
char* it = TasmotaGlobal.log_buffer;
it++; // Skip log_buffer_pointer