prefs: encode led_brightness too, not just decode; fix pinned test layout

companionPrefsEncode()/serverPrefsEncode() never wrote the led_brightness
byte that companionPrefsDecode()/serverPrefsDecode() already read,
desyncing every field that follows it by one byte on the companion side
(wifi_enabled/wifi_ssid/wifi_pwd) and silently truncating the server
format by one byte. Caught by CI's ASan/UBSan run on the host regression
suite: an out-of-bounds read/write in the pinned layout tests.

Since led_brightness never existed upstream, nothing already accounted
for it: fixing only the encoder still leaves the pinned byte tables and
the documented 272/311-byte totals (COMPANION_PREFS_SIZE/
SERVER_PREFS_SIZE, used by the real prefs stores too, not just tests)
one byte short of what the encoder now actually produces.

- PrefsCodec.h: bump both size constants (272->273, 311->312).
- PrefsCodec.cpp: add the missing w.put() in both encoders, mirroring
  the position already used by both decoders.
- prefs_codec_tests.cpp: add led_brightness to both layout tables at its
  real file offset (shifts wifi_enabled/wifi_ssid/wifi_pwd by one byte
  on the companion side; server's is appended last, nothing else
  shifts), extend both historical-boundary length lists with the new
  full-format length, and give it a non-default value in sample() so
  the layout/roundtrip tests actually exercise it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ZephCore T096
2026-09-30 17:38:54 +02:00
co-authored by Claude Sonnet 5
parent fd8de307f2
commit f8a4992ff0
3 changed files with 15 additions and 12 deletions
+3
View File
@@ -106,6 +106,7 @@ size_t companionPrefsEncode(const NodePrefs &p, uint8_t *buf, size_t cap)
w.put(&p.tz_offset, 1);
w.put(&p.leds_radio_mode, 1);
w.put(&p.leds_hb_mode, 1);
w.put(&p.led_brightness, 1);
w.put(&p.wifi_enabled, 1);
w.put(p.wifi_ssid, sizeof(p.wifi_ssid));
w.put(p.wifi_pwd, sizeof(p.wifi_pwd));
@@ -285,6 +286,8 @@ size_t serverPrefsEncode(const NodePrefs &prefs, uint8_t *buf, size_t cap)
/* LED activity/heartbeat modes (offsets 309-310) */
w.put(&prefs.leds_radio_mode, sizeof(prefs.leds_radio_mode));
w.put(&prefs.leds_hb_mode, sizeof(prefs.leds_hb_mode));
/* led_brightness (ZephCore extension, since 1.17.4), offset 311. */
w.put(&prefs.led_brightness, sizeof(prefs.led_brightness));
return w.off;
}