Skip to content

Commit 8d11a33

Browse files
Copilotsarpel
andcommitted
Add additional safety checks: placeholder detection, division by zero prevention
Co-authored-by: sarpel <7412192+sarpel@users.noreply.github.com>
1 parent db81c1c commit 8d11a33

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

src/adaptive_buffer.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ void AdaptiveBuffer::updateBufferSize(int32_t rssi)
8989
// Only log if size changed significantly (>10%)
9090
if (new_size != current_buffer_size)
9191
{
92+
// Prevent division by zero
93+
if (current_buffer_size == 0)
94+
{
95+
current_buffer_size = new_size;
96+
adjustment_count++;
97+
last_adjustment_time = now;
98+
return;
99+
}
100+
92101
int change_pct = ((int)new_size - (int)current_buffer_size) * 100 / (int)current_buffer_size;
93102

94103
if (abs(change_pct) >= 10)

src/config_validator.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class ConfigValidator {
7676
if (strlen(WIFI_SSID) == 0) {
7777
LOG_ERROR("WiFi SSID is empty - must configure WIFI_SSID in config.h");
7878
valid = false;
79+
} else if (strcmp(WIFI_SSID, "YOUR_WIFI_SSID") == 0) {
80+
LOG_ERROR("WiFi SSID is still set to default placeholder - must configure WIFI_SSID in config.h");
81+
valid = false;
7982
} else {
8083
LOG_INFO(" ✓ WiFi SSID configured");
8184
}
@@ -84,6 +87,9 @@ class ConfigValidator {
8487
if (strlen(WIFI_PASSWORD) == 0) {
8588
LOG_ERROR("WiFi password is empty - must configure WIFI_PASSWORD in config.h");
8689
valid = false;
90+
} else if (strcmp(WIFI_PASSWORD, "YOUR_WIFI_PASSWORD") == 0) {
91+
LOG_ERROR("WiFi password is still set to default placeholder - must configure WIFI_PASSWORD in config.h");
92+
valid = false;
8793
} else {
8894
LOG_INFO(" ✓ WiFi password configured");
8995
}
@@ -123,6 +129,9 @@ class ConfigValidator {
123129
if (strlen(SERVER_HOST) == 0) {
124130
LOG_ERROR("Server HOST is empty - must configure SERVER_HOST in config.h");
125131
valid = false;
132+
} else if (strcmp(SERVER_HOST, "YOUR_SERVER_IP") == 0) {
133+
LOG_ERROR("Server HOST is still set to default placeholder - must configure SERVER_HOST in config.h");
134+
valid = false;
126135
} else {
127136
LOG_INFO(" ✓ Server HOST configured: %s", SERVER_HOST);
128137
}

src/logger.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ void Logger::init(LogLevel level)
4646

4747
void Logger::log(LogLevel level, const char *file, int line, const char *fmt, ...)
4848
{
49+
// Validate input parameters
50+
if (file == nullptr || fmt == nullptr)
51+
{
52+
return; // Silently ignore invalid calls to prevent recursion
53+
}
54+
4955
if (level < min_level)
5056
return;
5157

src/main.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,12 @@ void checkMemoryHealth() {
119119
if (free_heap < MEMORY_CRITICAL_THRESHOLD) {
120120
LOG_CRITICAL("Critical low memory: %u bytes - system may crash", free_heap);
121121
// Consider restarting if critically low
122-
if (free_heap < MEMORY_CRITICAL_THRESHOLD / 2) {
122+
// Use a safer threshold calculation
123+
uint32_t emergency_threshold = MEMORY_CRITICAL_THRESHOLD / 2;
124+
if (emergency_threshold == 0) {
125+
emergency_threshold = 1000; // Minimum 1KB emergency threshold
126+
}
127+
if (free_heap < emergency_threshold) {
123128
LOG_CRITICAL("Memory critically low - initiating graceful restart");
124129
gracefulShutdown();
125130
ESP.restart();

0 commit comments

Comments
 (0)