26
26
# $CFLAGS, $CXXFLAGS C and C++ compiler flags.
27
27
# $LIB_FUZZING_ENGINE C++ compiler argument to link fuzz target against the prebuilt engine library (e.g. libFuzzer).
28
28
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
+
29
62
function 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
31
69
func=$2
32
70
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 && \
36
79
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
47
90
}
48
91
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
55
97
compile_fuzzer tests/fuzzers/keystore Fuzz fuzzKeystore
56
98
compile_fuzzer tests/fuzzers/txfetcher Fuzz fuzzTxfetcher
57
99
compile_fuzzer tests/fuzzers/rlp Fuzz fuzzRlp
58
100
compile_fuzzer tests/fuzzers/trie Fuzz fuzzTrie
59
101
compile_fuzzer tests/fuzzers/stacktrie Fuzz fuzzStackTrie
60
- compile_fuzzer tests/fuzzers/difficulty Fuzz fuzzDifficulty
102
+ compile_fuzzer tests/fuzzers/difficulty Fuzz fuzzDifficulty
61
103
62
104
compile_fuzzer tests/fuzzers/bls12381 FuzzG1Add fuzz_g1_add
63
105
compile_fuzzer tests/fuzzers/bls12381 FuzzG1Mul fuzz_g1_mul
@@ -69,6 +111,10 @@ compile_fuzzer tests/fuzzers/bls12381 FuzzPairing fuzz_pairing
69
111
compile_fuzzer tests/fuzzers/bls12381 FuzzMapG1 fuzz_map_g1
70
112
compile_fuzzer tests/fuzzers/bls12381 FuzzMapG2 fuzz_map_g2
71
113
114
+ # TODO: move this to tests/fuzzers, if possible
115
+ compile_fuzzer crypto/blake2b Fuzz fuzzBlake2b
116
+
117
+
72
118
# This doesn't work very well @TODO
73
119
# compile_fuzzertests/fuzzers/abi Fuzz fuzzAbi
74
120
0 commit comments