mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-10-28 11:14:58 +00:00
fix(weblog): guard against a weblog_buffer of 0 (pop_front on empty deque)
WebLogService::operator<< trims with `log_messages_.size() >= limit_log_messages_`. size() is unsigned, so with limit_log_messages_ == 0 the condition holds even for an empty deque and pop_front() runs on it - undefined behaviour, in practice heap corruption. On a PSRAM board the stored value survives a reboot, so the device crashes again as soon as the first log message is written. Nothing clamps the value on the way in: start() copies settings.weblog_buffer with no lower bound, the PSRAM branch of operator<< passes it straight into limit_log_messages_, and ArduinoJson's | in WebSettings::update() only substitutes the default for a missing or type-incompatible key - a stored 0 is a valid uint16_t. - operator<<: skip the trim loop on an empty deque - start(): keep the existing default when the stored value is 0 - getSetValues(): a missing or zero max_messages keeps the current size instead of storing 0 - WebSettings::update(): repair a stored 0, and derive the psram/no-psram default once instead of twice Refs #3237
This commit is contained in:
@@ -328,10 +328,12 @@ StateUpdateResult WebSettings::update(JsonObject root, WebSettings & settings) {
|
||||
settings.email_subject = root["email_subject"] | FACTORY_EMAIL_SUBJECT;
|
||||
|
||||
// if no psram limit weblog buffer to 25 messages
|
||||
if (EMSESP::system_.PSram() > 0) {
|
||||
settings.weblog_buffer = root["weblog_buffer"] | EMSESP_DEFAULT_WEBLOG_BUFFER;
|
||||
} else {
|
||||
settings.weblog_buffer = root["weblog_buffer"] | 25; // limit to 25 messages if no psram
|
||||
const uint16_t weblog_buffer_default = (EMSESP::system_.PSram() > 0) ? EMSESP_DEFAULT_WEBLOG_BUFFER : 25;
|
||||
settings.weblog_buffer = root["weblog_buffer"] | weblog_buffer_default;
|
||||
// a stored 0 is a valid uint16 and passes the | default above, but would make
|
||||
// limit_log_messages_ 0 in WebLogService
|
||||
if (settings.weblog_buffer == 0) {
|
||||
settings.weblog_buffer = weblog_buffer_default;
|
||||
}
|
||||
|
||||
// save the settings if changed from the webUI
|
||||
|
||||
Reference in New Issue
Block a user