Fix: stack smashing reboot loop when >64 contacts are stored#19
Open
pablo-mano wants to merge 1 commit into
Open
Fix: stack smashing reboot loop when >64 contacts are stored#19pablo-mano wants to merge 1 commit into
pablo-mano wants to merge 1 commit into
Conversation
…tactList The device crashed on every boot with "Stack smashing protect failure!" whenever more than 64 contacts were stored from a previous firmware. Root cause: `filtered_indices[64]` in `renderContactList()` was written with up to MAX_CONTACTS (200) entries — a 136-element overflow that corrupted the stack canary and triggered a reboot loop. Fixes: - Grow `filtered_indices` to `MAX_CONTACTS` and add bounds guards in both the filtered and unfiltered code paths - Raise Arduino loop task stack from 8 KB to 16 KB via `CONFIG_ARDUINO_LOOP_STACK_SIZE=16384` (headroom for BLE + NVS depth) - Remove stale inline `NodePrefs` redefinition in `target.cpp` (had wrong types: `uint8_t airtime_factor` / `uint8_t rx_delay_base` instead of `float`); use the canonical `NodePrefs.h` instead Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The device enters a permanent reboot loop with
Stack smashing protect failure!in the serial monitor. The crash appears immediately after boot, always at the same point in the log:Root cause
Buffer overflow in
renderContactList()(UITask.cppline 336):MAX_CONTACTSis 200, but the array was sized at 64. Any device with more than 64 stored contacts (carried over from a previous firmware) would write 136 extraintvalues past the end of the array, smashing the GCC stack canary and triggering a hard reboot.The backtrace was decoded with
xtensa-esp32s3-elf-addr2lineagainst the built ELF:0x42008e0b→UITask::renderContactList()(closing brace — canary check fires here)0x4200c6c5→UITask::loop()(caller)0x42007441→loop()inmain.cppsetup()completes successfully; the crash happens on the very firstloop()iteration whenrenderContactList()tries to render the contact list.Fix
1.
renderContactList()— fix the buffer overflowGrow the array to
MAX_CONTACTSand add bounds guards in both the filtered and unfiltered code paths so the array can never be overrun regardless of how many contacts are stored.2. Arduino loop task stack —
platformio.iniRaise the loop task stack from the default 8 KB to 16 KB via
CONFIG_ARDUINO_LOOP_STACK_SIZE=16384. The call chainsetup()→ BLE init → NVS/Preferences → M5Stack init consumes significantly more than 8 KB and was itself on the edge of overflowing before the buffer-overflow bug dominated.3.
target.cpp— remove stale inlineNodePrefsredefinitionThe
setSettingValue()GPS sync code contained a hand-rolled localNodePrefsstruct with wrong field types (uint8_t airtime_factor/uint8_t rx_delay_baseinstead offloat). While alignment padding causedgps_enabledto land at the same offset by coincidence, the mismatch was a latent correctness bug and a maintenance hazard. Replaced with a direct include ofNodePrefs.h.Test plan
pio run -e M5stack_cardputer_cap_lora1262_companion)RadioLibWrapper: noise_flooroutput)Stack smashing protect failure!no longer appears in serial output🤖 Generated with Claude Code