2626# $CFLAGS, $CXXFLAGS C and C++ compiler flags.
2727# $LIB_FUZZING_ENGINE C++ compiler argument to link fuzz target against the prebuilt engine library (e.g. libFuzzer).
2828
29+ # This sets the -coverpgk for the coverage report when the corpus is executed through go test
30+ coverpkg=" github.com/ethereum/go-ethereum/..."
31+
32+ function coverbuild {
33+ path=$1
34+ function=$2
35+ fuzzer=$3
36+ tags=" "
37+
38+ if [[ $# -eq 4 ]]; then
39+ tags=" -tags $4 "
40+ fi
41+ cd $path
42+ fuzzed_package=` pwd | rev | cut -d' /' -f 1 | rev`
43+ cp $GOPATH /ossfuzz_coverage_runner.go ./" ${function,,} " _test.go
44+ sed -i -e ' s/FuzzFunction/' $function ' /' ./" ${function,,} " _test.go
45+ sed -i -e ' s/mypackagebeingfuzzed/' $fuzzed_package ' /' ./" ${function,,} " _test.go
46+ sed -i -e ' s/TestFuzzCorpus/Test' $function ' Corpus/' ./" ${function,,} " _test.go
47+
48+ cat << DOG > $OUT /$fuzzer
49+ #/bin/sh
50+
51+ cd $OUT /$path
52+ go test -run Test${function} Corpus -v $tags -coverprofile \$ 1 -coverpkg $coverpkg
53+
54+ DOG
55+
56+ chmod +x $OUT /$fuzzer
57+ # echo "Built script $OUT/$fuzzer"
58+ # cat $OUT/$fuzzer
59+ cd -
60+ }
61+
2962function compile_fuzzer {
30- path=$SRC /go-ethereum/$1
63+ # Inputs:
64+ # $1: The package to fuzz, within go-ethereum
65+ # $2: The name of the fuzzing function
66+ # $3: The name to give to the final fuzzing-binary
67+
68+ path=$GOPATH /src/github.com/ethereum/go-ethereum/$1
3169 func=$2
3270 fuzzer=$3
33- corpusfile=" ${path} /testdata/${fuzzer} _seed_corpus.zip"
34- echo " Building $fuzzer (expecting corpus at $corpusfile )"
35- (cd $path && \
71+
72+ echo " Building $fuzzer "
73+
74+ # Do a coverage-build or a regular build
75+ if [[ $SANITIZER = * coverage* ]]; then
76+ coverbuild $path $func $fuzzer $coverpkg
77+ else
78+ (cd $path && \
3679 go-fuzz -func $func -o $WORK /$fuzzer .a . && \
37- echo " First stage built OK " && \
38- $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $WORK / $fuzzer .a -o $OUT / $fuzzer && \
39- echo " Second stage built ok " )
40-
41- # # Check if there exists a seed corpus file
42- if [ -f $corpusfile ]
43- then
44- cp $corpusfile $OUT /
45- echo " Found seed corpus: $corpusfile "
46- fi
80+ $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $WORK / $fuzzer .a -o $OUT / $fuzzer )
81+ fi
82+
83+ # # Check if there exists a seed corpus file
84+ corpusfile= " ${path} /testdata/ ${fuzzer} _seed_corpus.zip "
85+ if [ -f $corpusfile ]
86+ then
87+ cp $corpusfile $OUT /
88+ echo " Found seed corpus: $corpusfile "
89+ fi
4790}
4891
49- compile_fuzzer common/bitutil Fuzz fuzzBitutilCompress
50- compile_fuzzer crypto/bn256 FuzzAdd fuzzBn256Add
51- compile_fuzzer crypto/bn256 FuzzMul fuzzBn256Mul
52- compile_fuzzer crypto/bn256 FuzzPair fuzzBn256Pair
53- compile_fuzzer core/vm/runtime Fuzz fuzzVmRuntime
54- compile_fuzzer crypto/blake2b Fuzz fuzzBlake2b
92+ compile_fuzzer tests/fuzzers/bitutil Fuzz fuzzBitutilCompress
93+ compile_fuzzer tests/fuzzers/bn256 FuzzAdd fuzzBn256Add
94+ compile_fuzzer tests/fuzzers/bn256 FuzzMul fuzzBn256Mul
95+ compile_fuzzer tests/fuzzers/bn256 FuzzPair fuzzBn256Pair
96+ compile_fuzzer tests/fuzzers/runtime Fuzz fuzzVmRuntime
5597compile_fuzzer tests/fuzzers/keystore Fuzz fuzzKeystore
5698compile_fuzzer tests/fuzzers/txfetcher Fuzz fuzzTxfetcher
5799compile_fuzzer tests/fuzzers/rlp Fuzz fuzzRlp
58100compile_fuzzer tests/fuzzers/trie Fuzz fuzzTrie
59101compile_fuzzer tests/fuzzers/stacktrie Fuzz fuzzStackTrie
60- compile_fuzzer tests/fuzzers/difficulty Fuzz fuzzDifficulty
102+ compile_fuzzer tests/fuzzers/difficulty Fuzz fuzzDifficulty
61103
62104compile_fuzzer tests/fuzzers/bls12381 FuzzG1Add fuzz_g1_add
63105compile_fuzzer tests/fuzzers/bls12381 FuzzG1Mul fuzz_g1_mul
@@ -69,6 +111,10 @@ compile_fuzzer tests/fuzzers/bls12381 FuzzPairing fuzz_pairing
69111compile_fuzzer tests/fuzzers/bls12381 FuzzMapG1 fuzz_map_g1
70112compile_fuzzer tests/fuzzers/bls12381 FuzzMapG2 fuzz_map_g2
71113
114+ # TODO: move this to tests/fuzzers, if possible
115+ compile_fuzzer crypto/blake2b Fuzz fuzzBlake2b
116+
117+
72118# This doesn't work very well @TODO
73119# compile_fuzzertests/fuzzers/abi Fuzz fuzzAbi
74120
0 commit comments