Skip to content

Commit

Permalink
prevent padding end with zero's if the limit more than actually remai…
Browse files Browse the repository at this point in the history
…ning in the transport header / payload
  • Loading branch information
compscidr committed Oct 31, 2024
1 parent bb122fe commit f08897d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/kotlin/com/jasonernst/kanonproxy/icmp/IcmpFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.jasonernst.knet.transport.TransportHeader
import java.net.Inet6Address
import java.net.InetAddress
import java.nio.ByteBuffer
import kotlin.math.min

object IcmpFactory {
/**
Expand Down Expand Up @@ -71,8 +72,9 @@ object IcmpFactory {
// IPv6 header length, ICMPv6 destination unreachable min header length, IPv6 header length (the one that generated this to happen)
(mtu.toUInt() - IP6_HEADER_SIZE - DESTINATION_UNREACHABLE_HEADER_MIN_LENGTH - IP6_HEADER_SIZE).toInt()
}
val reducedTransportBuffer = ByteArray(limit)
System.arraycopy(originalTransportBufferAndPayloadBuffer.array(), 0, reducedTransportBuffer, 0, limit)
val actualLimit = min(limit, originalTransportBufferAndPayloadBuffer.limit())
val reducedTransportBuffer = ByteArray(actualLimit)
System.arraycopy(originalTransportBufferAndPayloadBuffer.array(), 0, reducedTransportBuffer, 0, actualLimit)
originalRequestBuffer.put(reducedTransportBuffer)
originalRequestBuffer.rewind()

Expand Down

0 comments on commit f08897d

Please sign in to comment.