From 9337b8df6644390f427162143ee8c83ad3db7c96 Mon Sep 17 00:00:00 2001 From: AdamKorcz Date: Sat, 12 Nov 2022 17:30:10 +0000 Subject: [PATCH] Fuzzing: Rewrite existing fuzzers to native go fuzzers Signed-off-by: AdamKorcz --- configuration/fuzz.go | 17 ----------------- configuration/fuzz_test.go | 15 +++++++++++++++ reference/fuzz.go | 13 ------------- reference/fuzz_test.go | 14 ++++++++++++++ registry/api/v2/fuzz.go | 13 ------------- registry/api/v2/fuzz_test.go | 13 +++++++++++++ 6 files changed, 42 insertions(+), 43 deletions(-) delete mode 100644 configuration/fuzz.go create mode 100644 configuration/fuzz_test.go delete mode 100644 reference/fuzz.go create mode 100644 reference/fuzz_test.go delete mode 100644 registry/api/v2/fuzz.go create mode 100644 registry/api/v2/fuzz_test.go diff --git a/configuration/fuzz.go b/configuration/fuzz.go deleted file mode 100644 index e176e6ab..00000000 --- a/configuration/fuzz.go +++ /dev/null @@ -1,17 +0,0 @@ -//go:build gofuzz -// +build gofuzz - -package configuration - -import ( - "bytes" -) - -// ParserFuzzer implements a fuzzer that targets Parser() -// Export before building -// nolint:deadcode -func parserFuzzer(data []byte) int { - rd := bytes.NewReader(data) - _, _ = Parse(rd) - return 1 -} diff --git a/configuration/fuzz_test.go b/configuration/fuzz_test.go new file mode 100644 index 00000000..5186c855 --- /dev/null +++ b/configuration/fuzz_test.go @@ -0,0 +1,15 @@ +package configuration + +import ( + "bytes" + "testing" +) + +// ParserFuzzer implements a fuzzer that targets Parser() +// nolint:deadcode +func FuzzConfigurationParse(f *testing.F) { + f.Fuzz(func(t *testing.T, data []byte) { + rd := bytes.NewReader(data) + _, _ = Parse(rd) + }) +} diff --git a/reference/fuzz.go b/reference/fuzz.go deleted file mode 100644 index ef9b0bf0..00000000 --- a/reference/fuzz.go +++ /dev/null @@ -1,13 +0,0 @@ -//go:build gofuzz -// +build gofuzz - -package reference - -// fuzzParseNormalizedNamed implements a fuzzer -// that targets ParseNormalizedNamed -// Export before building the fuzzer. -// nolint:deadcode -func fuzzParseNormalizedNamed(data []byte) int { - _, _ = ParseNormalizedNamed(string(data)) - return 1 -} diff --git a/reference/fuzz_test.go b/reference/fuzz_test.go new file mode 100644 index 00000000..c64c54e2 --- /dev/null +++ b/reference/fuzz_test.go @@ -0,0 +1,14 @@ +package reference + +import ( + "testing" +) + +// fuzzParseNormalizedNamed implements a fuzzer +// that targets ParseNormalizedNamed +// nolint:deadcode +func FuzzParseNormalizedNamed(f *testing.F) { + f.Fuzz(func(t *testing.T, data string) { + _, _ = ParseNormalizedNamed(data) + }) +} diff --git a/registry/api/v2/fuzz.go b/registry/api/v2/fuzz.go deleted file mode 100644 index 03974347..00000000 --- a/registry/api/v2/fuzz.go +++ /dev/null @@ -1,13 +0,0 @@ -//go:build gofuzz -// +build gofuzz - -package v2 - -// FuzzParseForwardedHeader implements a fuzzer -// that targets parseForwardedHeader -// Export before building -// nolint:deadcode -func fuzzParseForwardedHeader(data []byte) int { - _, _, _ = parseForwardedHeader(string(data)) - return 1 -} diff --git a/registry/api/v2/fuzz_test.go b/registry/api/v2/fuzz_test.go new file mode 100644 index 00000000..5985b7c3 --- /dev/null +++ b/registry/api/v2/fuzz_test.go @@ -0,0 +1,13 @@ +package v2 + +import ( + "testing" +) + +// FuzzParseForwardedHeader implements a fuzzer +// that targets parseForwardedHeader +func FuzzParseForwardedHeader(f *testing.F) { + f.Fuzz(func(t *testing.T, data string) { + _, _, _ = parseForwardedHeader(data) + }) +}