fix(companion): bound the build-date copy; fit the version stamp in the frame
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d3f327c158
commit
4ad170c03e
2 files changed
+31
-5
No files matched your search
@@ -1029,8 +1029,13 @@ void MyMesh::handleCmdFrame(size_t len) {
|
|||||||
uint32_t reported_ble_pin = _serial->isConnectionSecure() ? _prefs.ble_pin : 0;
|
uint32_t reported_ble_pin = _serial->isConnectionSecure() ? _prefs.ble_pin : 0;
|
||||||
memcpy(&out_frame[i], &reported_ble_pin, 4);
|
memcpy(&out_frame[i], &reported_ble_pin, 4);
|
||||||
i += 4;
|
i += 4;
|
||||||
memset(&out_frame[i], 0, 12);
|
// 12-byte field = 11 chars + NUL. strcpy() here was unbounded: the default
|
||||||
strcpy((char *)&out_frame[i], FIRMWARE_BUILD_DATE);
|
// 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;
|
i += 12;
|
||||||
StrHelper::strzcpy((char *)&out_frame[i], board.getManufacturerName(), 40);
|
StrHelper::strzcpy((char *)&out_frame[i], board.getManufacturerName(), 40);
|
||||||
i += 40;
|
i += 40;
|
||||||
|
|||||||
+24
-3
@@ -43,14 +43,35 @@ except Exception:
|
|||||||
|
|
||||||
sha, dirty = "nogit", ""
|
sha, dirty = "nogit", ""
|
||||||
try:
|
try:
|
||||||
sha = git(cwd, "rev-parse", "--short", "HEAD")
|
sha = git(cwd, "rev-parse", "--short=7", "HEAD")
|
||||||
if subprocess.call(["git", "diff", "--quiet"], cwd=cwd) != 0:
|
if subprocess.call(["git", "diff", "--quiet"], cwd=cwd) != 0:
|
||||||
dirty = "+"
|
dirty = "+"
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
version = "%s-tth-%s%s" % (base, sha, dirty)
|
# Both strings have to survive the companion protocol's fixed-width fields
|
||||||
build_date = datetime.now().strftime("%d %b %Y %H:%M")
|
# (RESP_CODE_DEVICE_INFO in companion_radio/MyMesh.cpp): 20 B for the version
|
||||||
|
# and 12 B for the build date, NUL included, so 19 and 11 usable characters.
|
||||||
|
# Anything longer is silently truncated on the wire -- which first showed up as
|
||||||
|
# a node reporting "v1.16.0-tth-956238c" for SHA 956238c3, and a build date of
|
||||||
|
# "04 Aug 2026 " with the time cut clean off. The repeater's text console has no
|
||||||
|
# such limit, but one format everywhere beats two.
|
||||||
|
VER_LIMIT, DATE_LIMIT = 19, 11
|
||||||
|
|
||||||
|
# Budget: base and the dirty marker are never sacrificed -- a lost '+' would
|
||||||
|
# turn an uncommitted build into something that looks reproducible. The SHA
|
||||||
|
# gives up characters instead; git needs 7 for uniqueness in a repo this size,
|
||||||
|
# so this only bites if upstream's version string grows unusually long.
|
||||||
|
marker = "-tth"
|
||||||
|
room = VER_LIMIT - len(base) - len(marker) - len(dirty)
|
||||||
|
version = "%s%s%s%s" % (base, marker, sha[:max(4, room)], dirty)
|
||||||
|
if len(version) > VER_LIMIT:
|
||||||
|
print("build_version.py: WARNING: %r is %d chars, will truncate to %d on "
|
||||||
|
"the companion protocol" % (version, len(version), VER_LIMIT))
|
||||||
|
|
||||||
|
# yymmdd hhmm = exactly 11. Not pretty, but complete and sortable; the readable
|
||||||
|
# "%d %b %Y %H:%M" is 17 and lost its time to the 12-byte field.
|
||||||
|
build_date = datetime.now().strftime("%y%m%d %H%M")[:DATE_LIMIT]
|
||||||
env.Append(CPPDEFINES=[
|
env.Append(CPPDEFINES=[
|
||||||
("FIRMWARE_VERSION", env.StringifyMacro(version)),
|
("FIRMWARE_VERSION", env.StringifyMacro(version)),
|
||||||
("FIRMWARE_BUILD_DATE", env.StringifyMacro(build_date)),
|
("FIRMWARE_BUILD_DATE", env.StringifyMacro(build_date)),
|
||||||
|
|||||||
Reference in new issue
Block a user