From d01f5777820c08cb3b48f5e9e3fbca5f0a988adb Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 31 May 2021 18:34:51 +0200 Subject: [PATCH] Add log buffer max size check --- tasmota/support.ino | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tasmota/support.ino b/tasmota/support.ino index 0054f8a01..8abb5d644 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -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