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)
| 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) |
| 19 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…