From 49e6701601c1f9dc140e0717e5f4bd1e36c61589 Mon Sep 17 00:00:00 2001 From: TeTeHacko Date: Tue, 1 Sep 2026 20:12:21 +0200 Subject: [PATCH] =?UTF-8?q?fix(mesh):=20TRACE=20si=20p=C5=99ipojoval=20ces?= =?UTF-8?q?tu=20za=20konec=20payloadu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5 (1M context) --- src/Mesh.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Mesh.cpp b/src/Mesh.cpp index acde5b82..a2e71e73 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -712,6 +712,27 @@ void Mesh::sendDirect(Packet* packet, const uint8_t* path, uint8_t path_len, uin uint8_t pri; if (packet->getPayloadType() == PAYLOAD_TYPE_TRACE) { // TRACE packets are different // for TRACE packets, path is appended to end of PAYLOAD. (path is used for SNR's) + // + // CUSTOM (TeTeHacko): a TRACE path is NOT capped at MAX_PATH_SIZE (see the note + // below), so this append has to be checked against the payload buffer itself. + // The companion guard on CMD_SEND_TRACE_PATH lets path_len reach 178, and a + // TRACE header is 9 bytes: 9+176 lands one byte past payload[184]. Measured on + // the host over all 194 path_len/path_sz combinations the guard admits -- two + // of them write past the end and demonstrably clobber `_snr`, the member that + // happens to sit right after the array. Those packets are then dropped by + // sendPacket() for exceeding the MTU, which is why nothing ever looked wrong + // from the outside. It is still a write out of bounds. + // + // Same fix as upstream PR #1662 (weebl2000), open and unmerged since Feb 2026. + // Its second half -- guarding the non-TRACE branch on path_len > MAX_PATH_SIZE + // -- is redundant here: that path goes through Packet::copyPath/writePath, + // which already refuses to write more than MAX_PATH_SIZE. + if ((size_t)packet->payload_len + path_len > sizeof(packet->payload)) { + MESH_DEBUG_PRINTLN("%s Mesh::sendDirect(): TRACE path too long, payload_len=%d path_len=%d", + getLogDateTime(), (int)packet->payload_len, (int)path_len); + _mgr->free(packet); + return; + } memcpy(&packet->payload[packet->payload_len], path, path_len); // NOTE: path_len here can be > 64, and NOT in the new scheme packet->payload_len += path_len;