Skip to content

Commit b436192

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 f19a825 commit b436192

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
@@ -155,7 +155,10 @@ DispatcherAction Mesh::onRecvPacket(Packet* pkt) {
155155
uint8_t path_len = data[k++];
156156
uint8_t hash_size = (path_len >> 6) + 1;
157157
uint8_t hash_count = path_len & 63;
158-
if (k + hash_size*hash_count + 1 > len) break; // bounds check: need path bytes + extra_type byte
158+
if (k + hash_size*hash_count + 1 > len) { // bounds check: need path bytes + extra_type byte
159+
MESH_DEBUG_PRINTLN("%s Mesh::onRecvPacket(): bad PATH payload format, path_len=%d len=%d", getLogDateTime(), (int)path_len, (int)len);
160+
break;
161+
}
159162
uint8_t* path = &data[k]; k += hash_size*hash_count;
160163
uint8_t extra_type = data[k++] & 0x0F; // upper 4 bits reserved for future use
161164
uint8_t* extra = &data[k];

0 commit comments

Comments
 (0)