TCPoptionCheck Accept function panic
- Dominant language
- Go
- Stars
- 6.8k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I get the following error when at random
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x9b195f]
goroutine 29 [running]:
encoding/binary.bigEndian.Uint16(...)
/usr/local/go/src/encoding/binary/binary.go:101
github.com/google/gopacket/reassembly.(*TCPOptionCheck).Accept(0xc00af40018, 0xc000b50500, 0x14fe345b, 0xed55cbe1f, 0x12257e0, 0x4e, 0x4e, 0x3, 0x0, 0x0, ...)
/go/pkg/mod/github.com/google/gopacket@v1.1.17/reassembly/tcpcheck.go:68 +0xaf
bitbucket.org/wenspire/dow/tcpreassembler.(*tcpStream).Accept(0xc00af40000, 0xc000b50500, 0x14fe345b, 0xed55cbe1f, 0x12257e0, 0x4e, 0x4e, 0x3, 0x0, 0x0, ...)
/src/tcpreassembler/reassembler.go:68 +0xbd
github.com/google/gopacket/reassembly.(*Assembler).AssembleWithContext(0xc0001f6480, 0x1, 0x4, 0x4, 0xeec639d5, 0x0, 0x5a120c0a, 0x0, 0xc000b50500, 0xcef640, ...)
/go/pkg/mod/github.com/google/gopacket@v1.1.17/reassembly/tcpassembly.go:668 +0x5ac
I run the packet decoding and TCP reassembly in different go routines and pass the TCP layer through a channel as following
for _, typ := range p.decodedLayers {
// IMPORTANT: copy the values we pass to the reassembly so they're not overriden here. FIXME: should be removed on above TODO implementation
switch typ {
case layers.LayerTypeEthernet:
p.tsClient.TSCounterAdd(parserCounters[EthHeadersBytes], len(p.eth.Contents))
case layers.LayerTypeIPv4:
ip4 := p.ip4 // this is a copy
netLayer = &ip4
p.tsClient.TSCounterAdd(parserCounters[IPv4HeadersBytes], len(p.ip4.Contents))
case layers.LayerTypeIPv6:
ip6 := p.ip6
netLayer = &ip6
p.tsClient.TSCounterAdd(parserCounters[IPv6HeadersBytes], len(p.ip6.Contents))
case layers.LayerTypeTCP:
tcp := p.tcp
if err := tcp.SetNetworkLayerForChecksum(netLayer); err != nil {
log.Error("couldn't set network layer for checksum: ", err)
}
p.reassembler.Enqueue(netLayer.NetworkFlow(), tcp, capInfo)
}
Is it possible that copying using "tcp:p.tcp" still leaves some shared data that could cause the access error?
Is the a right way to copy a layer
Thanks
Samuel
Contributor guide
Assessment
This issue has not been assessed yet.