fuzz.go 833 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // +build gofuzz
  2. // Use with https://github.com/dvyukov/go-fuzz
  3. package btf
  4. import (
  5. "bytes"
  6. "encoding/binary"
  7. "github.com/cilium/ebpf/internal"
  8. )
  9. func FuzzSpec(data []byte) int {
  10. if len(data) < binary.Size(btfHeader{}) {
  11. return -1
  12. }
  13. spec, err := loadNakedSpec(bytes.NewReader(data), internal.NativeEndian, nil, nil)
  14. if err != nil {
  15. if spec != nil {
  16. panic("spec is not nil")
  17. }
  18. return 0
  19. }
  20. if spec == nil {
  21. panic("spec is nil")
  22. }
  23. return 1
  24. }
  25. func FuzzExtInfo(data []byte) int {
  26. if len(data) < binary.Size(btfExtHeader{}) {
  27. return -1
  28. }
  29. table := stringTable("\x00foo\x00barfoo\x00")
  30. info, err := parseExtInfo(bytes.NewReader(data), internal.NativeEndian, table)
  31. if err != nil {
  32. if info != nil {
  33. panic("info is not nil")
  34. }
  35. return 0
  36. }
  37. if info == nil {
  38. panic("info is nil")
  39. }
  40. return 1
  41. }