mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-07-26 14:58:12 +00:00
fix: smaller audit items — strnlen, narrow-display guard, SNR precision
M2: CMD_SET_DEFAULT_FLOOD_SCOPE used strlen() on the frame's 31-byte name slot, which is not required to be NUL-terminated. Switched to strnlen() so the search can't run past the field into the 16-byte key. M4: NearbyScreen::renderDiscoverDetail computed strncpy(b64, ..., max_chars - 3) where max_chars came from display width. On very narrow displays (width < ~28 at 6 px font) this became negative. Skip the pub-key line entirely when max_chars < 4 so we don't risk a negative count and a bogus terminator. L1: SNR was shown as truncated integer dB. Switched the detail view and the 2-line discover cards to %.1f so they keep the 0.25 dB resolution (consistent with the ping popup, which already used %.1f). L4: Two fallback "?" sender placeholders used strncpy(buf, "?", sizeof(buf)) — functional but it memsets 21 unused bytes for a one-character string. Replaced with strcpy. M1 marked as not-a-bug after re-check: default_scope_name is char[31], so the n < 31 guard correctly admits the max 30-char string + NUL. FEATURES.md audit section updated with current status. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -2139,7 +2139,10 @@ void MyMesh::handleCmdFrame(size_t len) {
|
||||
writeOKFrame();
|
||||
} else if (cmd_frame[0] == CMD_SET_DEFAULT_FLOOD_SCOPE && len >= 1) {
|
||||
if (len >= 1+31+16) {
|
||||
int n = strlen((char *) &cmd_frame[1]);
|
||||
// strnlen, not strlen: the name field is always 31 bytes in the frame
|
||||
// even if the actual name is shorter, so we must bound the search to
|
||||
// avoid reading into the key (or past the frame) when no NUL is present.
|
||||
int n = (int)strnlen((char *) &cmd_frame[1], 31);
|
||||
if (n > 0 && n < 31) {
|
||||
strcpy(_prefs.default_scope_name, (char *) &cmd_frame[1]);
|
||||
memcpy(_prefs.default_scope_key, &cmd_frame[1+31], 16);
|
||||
|
||||
Reference in New Issue
Block a user