From d0ca0c330330270543d4971a641be55f0960e071 Mon Sep 17 00:00:00 2001 From: AdamKorcz Date: Tue, 20 Jul 2021 16:24:20 +0100 Subject: [PATCH] Fuzzing: Add 3 fuzzers Signed-off-by: AdamKorcz --- configuration/fuzz.go | 16 ++++++++++++++++ reference/fuzz.go | 12 ++++++++++++ registry/api/v2/fuzz.go | 12 ++++++++++++ script/oss_fuzz_build.sh | 9 +++++++++ 4 files changed, 49 insertions(+) create mode 100644 configuration/fuzz.go create mode 100644 reference/fuzz.go create mode 100644 registry/api/v2/fuzz.go create mode 100755 script/oss_fuzz_build.sh diff --git a/configuration/fuzz.go b/configuration/fuzz.go new file mode 100644 index 000000000..103bacddc --- /dev/null +++ b/configuration/fuzz.go @@ -0,0 +1,16 @@ +// +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/reference/fuzz.go b/reference/fuzz.go new file mode 100644 index 000000000..01a0dca9f --- /dev/null +++ b/reference/fuzz.go @@ -0,0 +1,12 @@ +// +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/registry/api/v2/fuzz.go b/registry/api/v2/fuzz.go new file mode 100644 index 000000000..24feeaac5 --- /dev/null +++ b/registry/api/v2/fuzz.go @@ -0,0 +1,12 @@ +// +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/script/oss_fuzz_build.sh b/script/oss_fuzz_build.sh new file mode 100755 index 000000000..e89fa8a95 --- /dev/null +++ b/script/oss_fuzz_build.sh @@ -0,0 +1,9 @@ +#!/bin/bash -eu + +sed 's/parserFuzzer/ParserFuzzer/g' -i ./configuration/fuzz.go +sed 's/fuzzParseNormalizedNamed/FuzzParseNormalizedNamed/g' -i ./reference/fuzz.go +sed 's/fuzzParseForwardedHeader/FuzzParseForwardedHeader/g' -i ./registry/api/v2/fuzz.go + +compile_go_fuzzer github.com/distribution/distribution/v3/configuration ParserFuzzer parser_fuzzer +compile_go_fuzzer github.com/distribution/distribution/v3/reference FuzzParseNormalizedNamed fuzz_parsed_normalized_named +compile_go_fuzzer github.com/distribution/distribution/v3/registry/api/v2 FuzzParseForwardedHeader fuzz_parse_forwarded_header