fuzz.go 851 B

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