Fix stack-buffer overflow in CLI reply buffers

The remote-CLI reply buffers in onPeerDataRecv() (repeater, room server,
sensor) and BaseChatMesh were sized temp[166] for a 5-byte datagram
header plus 161 bytes of reply. But MyMesh::handleCommand() first
reflects a 3-byte correlation prefix (e.g. 'aa|') into the reply, after
which CommonCLI commands may write up to 160 chars + NUL into the
remaining 158 bytes -- overflowing the buffer by 2 bytes (e.g. a full
'regions' listing via exportTo(reply, 160)).

Triggering this remotely crashes the node (observed as an unresponsive
repeater after a prefixed 'regions' query); the 2 out-of-bounds bytes
are a printable region-name character and a NUL.

Size the buffers for the full worst case instead:
5 header + 3 prefix + 160 reply + 1 NUL = 169.

Verified with a host ASan harness reproducing the exact layout:
prefixed 'regions' with a 25-region listing overflowed temp[166]
(BufStream::write, RegionMap.cpp) and now passes clean with temp[169];
unprefixed (serial) path unaffected.
This commit is contained in:
Valentin Metz committed 2026-11-11 05:30:54 +01:00
1 parent 06719e6877
commit f02d9d9e47
4 files changed
+8 -4

No files matched your search

+2 -1
View File
@@ -462,7 +462,8 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
mesh::Utils::sha256((uint8_t *)&ack_hash, 4, data, 5 + strlen((char *)&data[5]), client->id.pub_key,
PUB_KEY_SIZE);
uint8_t temp[166];
// 5-byte datagram header + 3-byte reflected CLI prefix + 160-byte reply text + NUL
uint8_t temp[169];
bool send_ack;
if (flags == TXT_TYPE_CLI_DATA || flags == TXT_TYPE_CLI_COMMAND) {
if (client->isAdmin()) {