• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2021 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16################################################################################
17
18cd "$GOPATH"/src/github.com/caddyserver/caddy/v2
19
20find . -name '*_fuzz.go' | while read -r target
21do
22# Arguments are :
23#     path of the package with the fuzz target
24#     name of the fuzz function
25#     name of the fuzzer to be built
26#     optional tag to be used by go build and such
27
28    fuzzed_func=$(grep -o "Fuzz[a-zA-Z]\+" "$target")
29    fuzzer_name=$(echo "$fuzzed_func" | sed -E 's/([A-Z])/-\L\1/g' | sed 's/^-//')
30    # find the relative directory and remove the first `.` (`./` is removed for root)
31    target_dir=$(dirname "$target"); target_dir="${target_dir//.}";
32    target_corpus_name="${fuzzer_name}_seed_corpus.zip"
33
34    curl -s -f -O "https://raw.githubusercontent.com/caddyserver/caddy/fuzz-seed-corpus/${target_corpus_name}" || true
35    compile_go_fuzzer github.com/caddyserver/caddy/v2"$target_dir" "$fuzzed_func" "$fuzzer_name" gofuzz
36done
37