From 8c26f30a7ce71721a1d6bd402baaf58ab80e5b93 Mon Sep 17 00:00:00 2001 From: Nicholas Jackson Date: Tue, 2 Jan 2024 11:08:48 -0800 Subject: [PATCH] chore: move cookie fuzz test to go 1.18 fuzzing --- .gitignore | 1 + cookie_test.go | 16 ++++++++++++++++ fuzzit/cookie/cookie_fuzz.go | 25 ------------------------- 3 files changed, 17 insertions(+), 25 deletions(-) delete mode 100644 fuzzit/cookie/cookie_fuzz.go diff --git a/.gitignore b/.gitignore index 035e3024f5..7673684160 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ tags .vscode .DS_Store vendor/ +testdata/fuzz diff --git a/cookie_test.go b/cookie_test.go index b4b81ac9ab..1a6c3a59d1 100644 --- a/cookie_test.go +++ b/cookie_test.go @@ -15,6 +15,22 @@ func TestCookiePanic(t *testing.T) { } } +func FuzzCookieParse(f *testing.F) { + inputs := []string{ + `xxx=yyy`, + `xxx=yyy; expires=Tue, 10 Nov 2009 23:00:00 GMT; domain=foobar.com; path=/a/b`, + " \n\t\"", + } + for _, input := range inputs { + f.Add([]byte(input)) + } + c := AcquireCookie() + defer ReleaseCookie(c) + f.Fuzz(func(t *testing.T, cookie []byte) { + _ = c.ParseBytes(cookie) + }) +} + func TestCookieValueWithEqualAndSpaceChars(t *testing.T) { t.Parallel() diff --git a/fuzzit/cookie/cookie_fuzz.go b/fuzzit/cookie/cookie_fuzz.go deleted file mode 100644 index 929513fcb4..0000000000 --- a/fuzzit/cookie/cookie_fuzz.go +++ /dev/null @@ -1,25 +0,0 @@ -//go:build gofuzz - -package fuzz - -import ( - "bytes" - - "github.com/valyala/fasthttp" -) - -func Fuzz(data []byte) int { - c := fasthttp.AcquireCookie() - defer fasthttp.ReleaseCookie(c) - - if err := c.ParseBytes(data); err != nil { - return 0 - } - - w := bytes.Buffer{} - if _, err := c.WriteTo(&w); err != nil { - return 0 - } - - return 1 -}