fix(companion): bound the build-date copy; fit the version stamp in the frame

Two halves of the same problem: the stamped version reached the device but
not the client.

RESP_CODE_DEVICE_INFO carries the build date in 12 bytes and the version in
20, NUL included -- 11 and 19 usable characters. The version field is
written with strzcpy() and truncates safely; the build date was a bare
strcpy() into a memset region, so a longer string simply ran past the end
into the manufacturer-name field. It never showed because strzcpy()
overwrote that field on the very next line. Benign today, and driven by a
compile-time constant rather than anything remote, but it is an unbounded
copy into a fixed frame slot and the only reason it was invisible is luck
about the write order. Now strzcpy(..., 12) like every other string there.

The stamp then had to fit. "v1.16.0-tth-0dbaba04" is 20 chars, so the node
reported "v1.16.0-tth-0dbaba0" -- readable, but a character short of the SHA
it was built from. "04 Aug 2026 11:28" is 17, so the time was cut clean off.
Now a 7-char SHA with a "-tth" marker (19 with the dirty '+', 18 without)
and a yymmdd hhmm date (11). The budget never sacrifices the base version or
the dirty marker -- a lost '+' would make an uncommitted build look
reproducible -- and warns instead of truncating silently if it ever cannot
fit.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5 committed 2026-08-04 11:43:53 +02:00
1 parent 0dbaba046c
commit 7c071d1515
2 files changed
+31 -5

No files matched your search

+7 -2
View File
@@ -1029,8 +1029,13 @@ void MyMesh::handleCmdFrame(size_t len) {
uint32_t reported_ble_pin = _serial->isConnectionSecure() ? _prefs.ble_pin : 0;
memcpy(&out_frame[i], &reported_ble_pin, 4);
i += 4;
memset(&out_frame[i], 0, 12);
strcpy((char *)&out_frame[i], FIRMWARE_BUILD_DATE);
// 12-byte field = 11 chars + NUL. strcpy() here was unbounded: the default
// FIRMWARE_BUILD_DATE literal ("6 Jun 2026") fits, but a stamped one from
// tools/build_version.py does not, and the overrun ran into the
// manufacturer-name field below -- invisibly, because strzcpy() overwrote it
// on the next line. strzcpy() truncates and NUL-pads instead (so the memset
// is redundant), same as every other string in this frame.
StrHelper::strzcpy((char *)&out_frame[i], FIRMWARE_BUILD_DATE, 12);
i += 12;
StrHelper::strzcpy((char *)&out_frame[i], board.getManufacturerName(), 40);
i += 40;