| #!/bin/bash -eu |
| # Copyright 2020 Google Inc. |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| ################################################################################ |
| |
| for PROJECT in ${SRC}/*; |
| do |
| PROJECT=$(basename ${PROJECT}) |
| |
| # A libyal project should have an ossfuzz directory and a synclibs.sh script. |
| if ! test -d ${SRC}/${PROJECT}/ossfuzz || ! test -x ${SRC}/${PROJECT}/synclibs.sh; |
| then |
| continue |
| fi |
| cd ${SRC}/${PROJECT} |
| |
| # Prepare the project source for build. |
| ./synclibs.sh |
| ./autogen.sh |
| ./configure --enable-shared=no |
| |
| # Build the project and fuzzer binaries. |
| make -j$(nproc) LIB_FUZZING_ENGINE=${LIB_FUZZING_ENGINE} |
| |
| # Download the test data if supported. |
| if test -x ./synctestdata.sh; |
| then |
| ./synctestdata.sh |
| fi |
| |
| # Copy the fuzzer binaries and test data to the output directory. |
| for FUZZ_TARGET in $(cd ossfuzz && find . -executable -type f); |
| do |
| FUZZ_TARGET=$(basename ${FUZZ_TARGET}) |
| |
| # Prefix the fuzzer binaries with the project name. |
| cp ossfuzz/${FUZZ_TARGET} ${OUT}/${PROJECT}_${FUZZ_TARGET} |
| |
| # Download the test data if supported. |
| LIBYAL_TYPE_NAME=${FUZZ_TARGET/_fuzzer/}; |
| |
| if test -f tests/data/${LIBYAL_TYPE_NAME/}.1; |
| then |
| (cd tests/data && zip ${OUT}/${PROJECT}_${FUZZ_TARGET}_seed_corpus.zip ${LIBYAL_TYPE_NAME}.*) |
| |
| elif test -d tests/input/public; |
| then |
| (cd tests/input/public && zip ${OUT}/${PROJECT}_${FUZZ_TARGET}_seed_corpus.zip *) |
| |
| else |
| echo "Missing test data for seed corpus." |
| exit 1 |
| fi |
| done |
| done |