1
0

outbound_fuzz_test.go 1008 B

12345678910111213141516171819202122232425262728
  1. package link
  2. import "testing"
  3. // FuzzParseLink asserts the parser never panics and upholds its (result, error) contract
  4. // — exactly one non-nil. It base64-decodes and type-asserts attacker-controllable JSON,
  5. // the classic panic source.
  6. func FuzzParseLink(f *testing.F) {
  7. seeds := []string{
  8. "",
  9. "not-a-link",
  10. "vmess://eyJ2IjoiMiIsInBzIjoidCIsImFkZCI6ImEuY29tIiwicG9ydCI6IjQ0MyIsImlkIjoiMTExMTExMTEtMjIyMi00MzMzLTg0NDQtNTU1NTU1NTU1NTU1IiwibmV0IjoidGNwIn0=",
  11. "vless://[email protected]:443?type=tcp&security=none#x",
  12. "trojan://[email protected]:443?security=tls#x",
  13. "ss://[email protected]:8388#x",
  14. "hysteria2://[email protected]:443?sni=a.com#x",
  15. "wireguard://[email protected]:51820?publickey=pub#x",
  16. }
  17. for _, s := range seeds {
  18. f.Add(s)
  19. }
  20. f.Fuzz(func(t *testing.T, s string) {
  21. res, err := ParseLink(s)
  22. if (res == nil) == (err == nil) {
  23. t.Fatalf("ParseLink(%q): exactly one of (result, error) must be non-nil; got res=%v err=%v", s, res, err)
  24. }
  25. })
  26. }