Skip to content

Commit fe3304d

Browse files
committed
fix bounds check on PAYLOAD_TYPE_PATH decrypted data
The path_len field inside the decrypted PATH payload was used to advance the parse cursor without validating it against the actual decrypted data length. A malicious peer sharing a key could craft a PATH packet with an oversized path_len, causing out-of-bounds reads past the decrypted buffer when accessing the extra_type byte and extra data pointer. Add a bounds check after reading path_len to ensure the decrypted buffer contains enough bytes for the claimed path plus the mandatory extra_type byte before dereferencing.
1 parent e6e87fb commit fe3304d

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

src/Mesh.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ 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
161162
uint8_t* path = &data[k]; k += path_len;
162163
uint8_t extra_type = data[k++] & 0x0F; // upper 4 bits reserved for future use
163164
uint8_t* extra = &data[k];

0 commit comments

Comments
 (0)