MCPcopy
hub / github.com/google/gopacket / FuzzLayer

Function FuzzLayer

layers/fuzz_layer.go:19–39  ·  view source on GitHub ↗

FuzzLayer is a fuzz target for the layers package of gopacket A fuzz target is a function processing a binary blob (byte slice) The process here is to interpret this data as a packet, and print the layers contents. The decoding options and the starting layer are encoded in the first bytes. The funct

(data []byte)

Source from the content-addressed store, hash-verified

17// The decoding options and the starting layer are encoded in the first bytes.
18// The function returns 1 if this is a valid packet (no error layer)
19func FuzzLayer(data []byte) int {
20 if len(data) < 3 {
21 return 0
22 }
23 // use the first two bytes to choose the top level layer
24 startLayer := binary.BigEndian.Uint16(data[:2])
25 var fuzzOpts = gopacket.DecodeOptions{
26 Lazy: data[2]&0x1 != 0,
27 NoCopy: data[2]&0x2 != 0,
28 SkipDecodeRecovery: data[2]&0x4 != 0,
29 DecodeStreamsAsDatagrams: data[2]&0x8 != 0,
30 }
31 p := gopacket.NewPacket(data[3:], gopacket.LayerType(startLayer), fuzzOpts)
32 for _, l := range p.Layers() {
33 gopacket.LayerString(l)
34 }
35 if p.ErrorLayer() != nil {
36 return 0
37 }
38 return 1
39}

Callers

nothing calls this directly

Calls 5

LayersMethod · 0.95
ErrorLayerMethod · 0.95
NewPacketFunction · 0.92
LayerTypeTypeAlias · 0.92
LayerStringFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…