Skip to content

Commit 7beb966

Browse files
committed
add debug log for malformed PATH payload
Log path_len and len when the bounds check fails, making it easier to diagnose malformed or corrupt packets during development.
1 parent fe3304d commit 7beb966

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/Mesh.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ DispatcherAction Mesh::onRecvPacket(Packet* pkt) {
158158
if (pkt->getPayloadType() == PAYLOAD_TYPE_PATH) {
159159
int k = 0;
160160
uint8_t path_len = data[k++];
161-
if (k + path_len + 1 > len) break; // bounds check: need path_len bytes + extra_type byte
161+
if (k + path_len + 1 > len) { // bounds check: need path_len bytes + extra_type byte
162+
MESH_DEBUG_PRINTLN("%s Mesh::onRecvPacket(): bad PATH payload format, path_len=%d len=%d", getLogDateTime(), (int)path_len, (int)len);
163+
break;
164+
}
162165
uint8_t* path = &data[k]; k += path_len;
163166
uint8_t extra_type = data[k++] & 0x0F; // upper 4 bits reserved for future use
164167
uint8_t* extra = &data[k];

0 commit comments

Comments
 (0)