1#!/bin/bash -eu 2# Copyright 2018 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# "Build the project" is a no-op. There is no "./configure.sh && make" dance. 19# Wuffs' generated C files are "drop-in libraries" a la 20# http://gpfault.net/posts/drop-in-libraries.txt.html 21 22for f in fuzz/c/std/*_fuzzer.c*; do 23 # Extract the format name (such as "gzip", from the C or C++ file name, 24 # "fuzz/c/std/gzip_fuzzer.c") and make the "gzip_fuzzer" binary. First 25 # compile the (C or C++) Wuffs code... 26 extension="${f##*.}" 27 if [ "$extension" = "c" ]; then 28 echo "Building (C) $f" 29 b=$(basename $f _fuzzer.c) 30 $CC $CFLAGS -c $f -o $WORK/${b}_fuzzer.o 31 elif [ "$extension" = "cc" ]; then 32 if [[ $LIB_FUZZING_ENGINE == *"DataFlow"* ]]; then 33 # Linking (below) with "--engine dataflow" works with the C fuzzers but 34 # not the C++ ones. With C++, we get errors like `undefined reference to 35 # `dfs$_ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED2Ev'` 36 # 37 # This is possibly "DFsan instrumented dependencies" 38 # https://github.com/google/oss-fuzz/issues/3388 39 echo "Skipping (C++) $f" 40 continue 41 fi 42 echo "Building (C++) $f" 43 b=$(basename $f _fuzzer.cc) 44 $CXX $CXXFLAGS -c $f -o $WORK/${b}_fuzzer.o 45 else 46 continue 47 fi 48 49 # ...then link the (C++) fuzzing library. 50 $CXX $CXXFLAGS $WORK/${b}_fuzzer.o -o $OUT/${b}_fuzzer $LIB_FUZZING_ENGINE 51 52 # Make the optional "gzip_fuzzer_seed_corpus.zip" archive. This means 53 # extracting the "foo/bar/*.gz" out of the matching "gzip: foo/bar/*.gz" 54 # lines in fuzz/c/std/seed_corpora.txt. 55 # 56 # The seed_corpora.txt lines can contain multiple entries, combining 57 # independent corpora. A naive "zip --junk-paths" of all those files can fail 58 # if there are duplicate file names, which can easily happen if the file name 59 # is a hash of its contents and the contents are a (trivial) minimal 60 # reproducer. We use a de-duplication step of copying all of those files into 61 # a single directory. Doing that in a single "cp" or "mv" call can fail with 62 # "will not overwrite just-created 'foo/etc' with 'bar/etc'", so we make 63 # multiple calls, each copying one file at a time. Later duplicates overwrite 64 # earlier duplicates. It's OK if the contents aren't identical. The result is 65 # still a valid uber-corpus of seed files. 66 seeds=$(sed -n -e "/^$b:/s/^$b: *//p" fuzz/c/std/seed_corpora.txt) 67 if [ -n "$seeds" ]; then 68 mkdir ${b}_fuzzer_seed_corpus 69 for s in $seeds; do 70 cp $s ${b}_fuzzer_seed_corpus 71 done 72 zip --junk-paths --recurse-paths $OUT/${b}_fuzzer_seed_corpus.zip ${b}_fuzzer_seed_corpus 73 rm -rf ${b}_fuzzer_seed_corpus 74 fi 75done 76