1
- # /bin/bash -eu
2
- # Copyright 2020 Google Inc.
1
+ #! /bin/bash -eu
2
+ # Copyright 2022 Google LLC
3
3
#
4
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
5
# you may not use this file except in compliance with the License.
15
15
#
16
16
# ###############################################################################
17
17
18
- # This file is for integration with Google OSS-Fuzz.
19
- # The following ENV variables are available when executing on OSS-fuzz:
20
- #
21
- # /out/ $OUT Directory to store build artifacts (fuzz targets, dictionaries, options files, seed corpus archives).
22
- # /src/ $SRC Directory to checkout source files.
23
- # /work/ $WORK Directory to store intermediate files.
24
- #
25
- # $CC, $CXX, $CCC The C and C++ compiler binaries.
26
- # $CFLAGS, $CXXFLAGS C and C++ compiler flags.
27
- # $LIB_FUZZING_ENGINE C++ compiler argument to link fuzz target against the prebuilt engine library (e.g. libFuzzer).
28
-
29
18
# This sets the -coverpgk for the coverage report when the corpus is executed through go test
30
19
coverpkg=" github.com/ethereum/go-ethereum/..."
31
20
59
48
cd -
60
49
}
61
50
62
- function compile_fuzzer {
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
51
+ function build_native_go_fuzzer() {
52
+ fuzzer=$1
53
+ function=$2
54
+ path=$3
55
+ tags=" -tags gofuzz"
56
+
57
+ if [[ $SANITIZER == * coverage* ]]; then
58
+ coverbuild $path $function $fuzzer $coverpkg
59
+ else
60
+ go-118-fuzz-build $tags -o $fuzzer .a -func $function $path
61
+ $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer .a -o $OUT /$fuzzer
62
+ fi
63
+ }
67
64
65
+ function compile_fuzzer() {
68
66
path=$GOPATH /src/github.com/ethereum/go-ethereum/$1
69
- func =$2
67
+ function =$2
70
68
fuzzer=$3
71
69
72
70
echo " Building $fuzzer "
71
+ cd $path
72
+
73
+ # Install build dependencies
74
+ go install github.com/AdamKorcz/go-118-fuzz-build@latest
75
+ go get github.com/AdamKorcz/go-118-fuzz-build/testing
73
76
74
- # Do a coverage-build or a regular build
75
- if [[ $SANITIZER = * coverage* ]]; then
76
- coverbuild $path $func $fuzzer $coverpkg
77
+ # Test if file contains a line with "func $function(" and "testing.F".
78
+ if [ $( grep -r " func $function (" $path | grep " testing.F" | wc -l) -eq 1 ]
79
+ then
80
+ build_native_go_fuzzer $fuzzer $function $path
77
81
else
78
- (cd $path && \
79
- go-fuzz -func $func -o $WORK /$fuzzer .a . && \
80
- $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $WORK /$fuzzer .a -o $OUT /$fuzzer )
82
+ echo " Could not find the function: func ${function} (f *testing.F)"
81
83
fi
82
84
83
85
# # Check if there exists a seed corpus file
@@ -87,9 +89,11 @@ function compile_fuzzer {
87
89
cp $corpusfile $OUT /
88
90
echo " Found seed corpus: $corpusfile "
89
91
fi
92
+ cd -
90
93
}
91
94
92
- compile_fuzzer tests/fuzzers/bitutil Fuzz fuzzBitutilCompress
95
+ compile_fuzzer tests/fuzzers/bitutil FuzzEncoder fuzzBitutilEncoder
96
+ compile_fuzzer tests/fuzzers/bitutil FuzzDecoder fuzzBitutilDecoder
93
97
compile_fuzzer tests/fuzzers/bn256 FuzzAdd fuzzBn256Add
94
98
compile_fuzzer tests/fuzzers/bn256 FuzzMul fuzzBn256Mul
95
99
compile_fuzzer tests/fuzzers/bn256 FuzzPair fuzzBn256Pair
0 commit comments