github.com/phillinzzz/newBsc@v1.1.6/oss-fuzz.sh (about) 1 #/bin/bash -eu 2 # Copyright 2020 Google Inc. 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 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 # This sets the -coverpgk for the coverage report when the corpus is executed through go test 30 coverpkg="github.com/phillinzzz/newBsc/..." 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 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 67 68 path=$GOPATH/src/github.com/phillinzzz/newBsc/$1 69 func=$2 70 fuzzer=$3 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 && \ 79 go-fuzz -func $func -o $WORK/$fuzzer.a . && \ 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 90 } 91 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 97 compile_fuzzer tests/fuzzers/keystore Fuzz fuzzKeystore 98 compile_fuzzer tests/fuzzers/txfetcher Fuzz fuzzTxfetcher 99 compile_fuzzer tests/fuzzers/rlp Fuzz fuzzRlp 100 compile_fuzzer tests/fuzzers/trie Fuzz fuzzTrie 101 compile_fuzzer tests/fuzzers/stacktrie Fuzz fuzzStackTrie 102 compile_fuzzer tests/fuzzers/difficulty Fuzz fuzzDifficulty 103 compile_fuzzer tests/fuzzers/abi Fuzz fuzzAbi 104 compile_fuzzer tests/fuzzers/les Fuzz fuzzLes 105 compile_fuzzer tests/fuzzers/vflux FuzzClientPool fuzzClientPool 106 107 compile_fuzzer tests/fuzzers/bls12381 FuzzG1Add fuzz_g1_add 108 compile_fuzzer tests/fuzzers/bls12381 FuzzG1Mul fuzz_g1_mul 109 compile_fuzzer tests/fuzzers/bls12381 FuzzG1MultiExp fuzz_g1_multiexp 110 compile_fuzzer tests/fuzzers/bls12381 FuzzG2Add fuzz_g2_add 111 compile_fuzzer tests/fuzzers/bls12381 FuzzG2Mul fuzz_g2_mul 112 compile_fuzzer tests/fuzzers/bls12381 FuzzG2MultiExp fuzz_g2_multiexp 113 compile_fuzzer tests/fuzzers/bls12381 FuzzPairing fuzz_pairing 114 compile_fuzzer tests/fuzzers/bls12381 FuzzMapG1 fuzz_map_g1 115 compile_fuzzer tests/fuzzers/bls12381 FuzzMapG2 fuzz_map_g2 116 117 compile_fuzzer tests/fuzzers/bls12381 FuzzCrossG1Add fuzz_cross_g1_add 118 compile_fuzzer tests/fuzzers/bls12381 FuzzCrossG1MultiExp fuzz_cross_g1_multiexp 119 compile_fuzzer tests/fuzzers/bls12381 FuzzCrossG2Add fuzz_cross_g2_add 120 compile_fuzzer tests/fuzzers/bls12381 FuzzCrossPairing fuzz_cross_pairing 121 122 #TODO: move this to tests/fuzzers, if possible 123 compile_fuzzer crypto/blake2b Fuzz fuzzBlake2b