2022-02-08 19:57:00 +00:00
|
|
|
#!/bin/bash -eu
|
|
|
|
# Copyright 2022 Google LLC
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
function build_native_go_fuzzer() {
|
|
|
|
fuzzer=$1
|
|
|
|
function=$2
|
|
|
|
path=$3
|
|
|
|
tags="-tags gofuzz"
|
|
|
|
|
2022-11-21 17:55:11 +00:00
|
|
|
if [[ $SANITIZER == *coverage* ]]; then
|
|
|
|
current_dir=$(pwd)
|
|
|
|
mkdir $OUT/rawfuzzers || true
|
|
|
|
cd $abs_file_dir
|
2023-09-05 21:31:53 +00:00
|
|
|
go test $tags -c -run $fuzzer -o $OUT/$fuzzer -cover
|
2022-11-21 17:55:11 +00:00
|
|
|
cp "${fuzzer_filename}" "${OUT}/rawfuzzers/${fuzzer}"
|
2023-09-13 18:04:44 +00:00
|
|
|
|
|
|
|
fuzzed_repo=$(go list $tags -f {{.Module}} "$path")
|
|
|
|
abspath_repo=`go list -m $tags -f {{.Dir}} $fuzzed_repo || go list $tags -f {{.Dir}} $fuzzed_repo`
|
|
|
|
# give equivalence to absolute paths in another file, as go test -cover uses golangish pkg.Dir
|
|
|
|
echo "s=$fuzzed_repo"="$abspath_repo"= > $OUT/$fuzzer.gocovpath
|
|
|
|
|
2022-11-21 17:55:11 +00:00
|
|
|
cd $current_dir
|
2022-02-08 19:57:00 +00:00
|
|
|
else
|
2023-08-29 03:11:42 +00:00
|
|
|
go-118-fuzz-build $tags -o $fuzzer.a -func $function $abs_file_dir
|
2022-02-08 19:57:00 +00:00
|
|
|
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o $OUT/$fuzzer
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
path=$1
|
|
|
|
function=$2
|
|
|
|
fuzzer=$3
|
|
|
|
tags="-tags gofuzz"
|
|
|
|
|
|
|
|
# Get absolute path.
|
|
|
|
abs_file_dir=$(go list $tags -f {{.Dir}} $path)
|
|
|
|
|
|
|
|
# TODO(adamkorcz): Get rid of "-r" flag here.
|
2022-08-17 03:03:34 +00:00
|
|
|
fuzzer_filename=$(grep -r -l --include='*.go' -s "$function" "${abs_file_dir}")
|
2022-02-08 19:57:00 +00:00
|
|
|
|
|
|
|
# Test if file contains a line with "func $function" and "testing.F".
|
|
|
|
if [ $(grep -r "func $function" $fuzzer_filename | grep "testing.F" | wc -l) -eq 1 ]
|
|
|
|
then
|
|
|
|
build_native_go_fuzzer $fuzzer $function $abs_file_dir
|
|
|
|
else
|
|
|
|
echo "Could not find the function: func ${function}(f *testing.F)"
|
|
|
|
fi
|