Skip to content

Commit

Permalink
better handling of packets with malformed lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
compscidr committed Dec 24, 2024
1 parent d85ef15 commit bfd86eb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/kotlin/com/jasonernst/knet/Packet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ open class Packet(
"Packet too short to obtain entire payload, have ${stream.remaining()}, expecting $expectedRemaining",
)
}
if (expectedRemaining < 0) {
logger.warn(
"Expected remaining is negative, something is wrong: {} IP total length: {} IP header length: {} next header length: {}",
expectedRemaining,
ipHeader.getTotalLength(),
ipHeader.getHeaderLength(),
nextHeader.getHeaderLength(),
)
return Packet(ipHeader, nextHeader, ByteArray(0))
}
val payload = ByteArray(expectedRemaining)
stream.get(payload)
return Packet(ipHeader, nextHeader, payload)
Expand Down

0 comments on commit bfd86eb

Please sign in to comment.