mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-07-26 23:08:11 +00:00
fix(companion): channel save/lookup hardening + trail count guard
Address the open items from the FEATURES.md audit backlog: - saveChannels() now skips unused slots (all-zero secret) instead of writing all 40 every time, so /channels2 holds only configured channels (was always ~2.7 KB) and wears the flash less. loadChannels() already compacted empties on read, so the loaded result is unchanged. - findChannelIdx() returns -1 for an all-zero secret, so a corrupted/empty channel can't match an unused all-zero slot and misroute messages. - TrailStore gains a static_assert that CAPACITY fits the uint16_t save header count, failing the build instead of silently truncating. Also re-classify two audit items verified to be non-issues in current code: the bot strstr "199-char" truncation (BOT_SCRATCH=200 >= MAX_TEXT_LEN =160, unreachable) and the MSG_PICK reply title (rlen clamped to 20, so title[24] never overflows). Verified: WioTrackerL1_companion_solo_dual builds clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -906,6 +906,11 @@ bool BaseChatMesh::setChannel(int idx, const ChannelDetails& src) {
|
||||
return false;
|
||||
}
|
||||
int BaseChatMesh::findChannelIdx(const mesh::GroupChannel& ch) {
|
||||
// An all-zero secret is never a real channel key; without this guard it would
|
||||
// match the first uninitialised (all-zero) slot and misroute incoming messages.
|
||||
bool empty = true;
|
||||
for (int b = 0; b < (int)sizeof(ch.secret); b++) if (ch.secret[b]) { empty = false; break; }
|
||||
if (empty) return -1;
|
||||
for (int i = 0; i < MAX_GROUP_CHANNELS; i++) {
|
||||
if (memcmp(ch.secret, channels[i].channel.secret, sizeof(ch.secret)) == 0) return i;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user