Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix panic with invalid fragmented ipv6 packet #684

Merged
merged 5 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions collectors/sniffer_afpacket_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (c *AfpacketSniffer) Run() {
if packet.NetworkLayer().LayerType() == layers.LayerTypeIPv4 {
ip4 := packet.NetworkLayer().(*layers.IPv4)
if ip4.Flags&layers.IPv4MoreFragments == 1 || ip4.FragOffset > 0 {
fragIP4Chan <- packet
// fragIP4Chan <- packet
continue
}
}
Expand All @@ -209,7 +209,7 @@ func (c *AfpacketSniffer) Run() {
if packet.NetworkLayer().LayerType() == layers.LayerTypeIPv6 {
v6frag := packet.Layer(layers.LayerTypeIPv6Fragment)
if v6frag != nil {
fragIP6Chan <- packet
// fragIP6Chan <- packet
continue
}
}
Expand Down
40 changes: 40 additions & 0 deletions netutils/ipdefrag_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package netutils

// TODO
/*
func createIPv6FragmentPacketWithNilLayer() gopacket.Packet {
// IPv6 layer
ipLayer := &layers.IPv6{
Version: 6,
NextHeader: layers.IPProtocolIPv6Fragment, // Next header is Fragmentation Header
HopLimit: 64,
SrcIP: net.ParseIP("2001:db8::1"),
DstIP: net.ParseIP("2001:db8::2"),
}

// Create a packet with nil IPv6Fragment layer
builder := gopacket.NewSerializeBuffer()
ipLayer.SerializeTo(builder, gopacket.SerializeOptions{})
// Set the IPv6 layer manually
packet := gopacket.NewPacket(builder.Bytes(), layers.LayerTypeIPv6, gopacket.Default)
// Remove IPv6Fragment layer
packet.Layer(layers.LayerTypeIPv6Fragment).(*layers.IPv6Fragment).Payload = nil

return packet
}


func TestIpDefrag_WithNilIPv6Fragment(t *testing.T) {
defragger := NewIPDefragmenter()

// Create an IPv6 packet with nil IPv6Fragment layer
packet := createIPv6FragmentPacketWithNilLayer()


// This packet has a nil IPv6Fragment layer, which should trigger an error
_, err := defragger.DefragIP(packet)
if err == nil {
t.Errorf("Expected error, got nil")
}
}
*/
Loading