| 12345678910111213141516171819202122232425262728 |
- package link
- import "testing"
- // FuzzParseLink asserts the parser never panics and upholds its (result, error) contract
- // — exactly one non-nil. It base64-decodes and type-asserts attacker-controllable JSON,
- // the classic panic source.
- func FuzzParseLink(f *testing.F) {
- seeds := []string{
- "",
- "not-a-link",
- "vmess://eyJ2IjoiMiIsInBzIjoidCIsImFkZCI6ImEuY29tIiwicG9ydCI6IjQ0MyIsImlkIjoiMTExMTExMTEtMjIyMi00MzMzLTg0NDQtNTU1NTU1NTU1NTU1IiwibmV0IjoidGNwIn0=",
- "vless://[email protected]:443?type=tcp&security=none#x",
- "trojan://[email protected]:443?security=tls#x",
- "ss://[email protected]:8388#x",
- "hysteria2://[email protected]:443?sni=a.com#x",
- "wireguard://[email protected]:51820?publickey=pub#x",
- }
- for _, s := range seeds {
- f.Add(s)
- }
- f.Fuzz(func(t *testing.T, s string) {
- res, err := ParseLink(s)
- if (res == nil) == (err == nil) {
- t.Fatalf("ParseLink(%q): exactly one of (result, error) must be non-nil; got res=%v err=%v", s, res, err)
- }
- })
- }
|