From 01364bf2b77ec69340a359d5d628e1ce012eb6ee Mon Sep 17 00:00:00 2001 From: Mike Aizatsky Date: Fri, 18 Nov 2016 14:53:09 -0800 Subject: [PATCH] [infra] extracting base-runner image --- infra/base-images/Jenkinsfile | 24 +++++++---- infra/base-images/all.sh | 1 + infra/base-images/base-runner/Dockerfile | 20 +++++++++ infra/base-images/base-runner/run_fuzzer | 41 ++++++++++++++++++ infra/base-images/base-runner/test_all | 53 ++++++++++++++++++++++++ infra/push-images/Jenkinsfile | 2 +- 6 files changed, 131 insertions(+), 10 deletions(-) create mode 100644 infra/base-images/base-runner/Dockerfile create mode 100755 infra/base-images/base-runner/run_fuzzer create mode 100755 infra/base-images/base-runner/test_all diff --git a/infra/base-images/Jenkinsfile b/infra/base-images/Jenkinsfile index 1b43143cb..af380d825 100644 --- a/infra/base-images/Jenkinsfile +++ b/infra/base-images/Jenkinsfile @@ -21,15 +21,21 @@ def dockerOptions="--no-cache" node { git url: 'https://github.com/google/oss-fuzz/' - stage name: 'ossfuzz/base', concurrency: 1 - sh "docker build $dockerOptions --pull -t ossfuzz/base infra/base-images/base" - stage name: 'ossfuzz/base-clang', concurrency: 1 - sh "docker build $dockerOptions -t ossfuzz/base-clang infra/base-images/base-clang" - - stage name: 'ossfuzz/base-libfuzzer', concurrency: 1 - sh "docker build $dockerOptions -t ossfuzz/base-libfuzzer infra/base-images/base-libfuzzer" + dir ("infra/base-images") { + stage name: 'ossfuzz/base', concurrency: 1 + sh "docker build $dockerOptions --pull -t ossfuzz/base base" - stage name: 'ossfuzz/libfuzzer-runner', concurrency: 1 - sh "docker build $dockerOptions -t ossfuzz/libfuzzer-runner infra/base-images/libfuzzer-runner" + stage name: 'ossfuzz/base-clang', concurrency: 1 + sh "docker build $dockerOptions -t ossfuzz/base-clang base-clang" + + stage name: 'ossfuzz/base-libfuzzer', concurrency: 1 + sh "docker build $dockerOptions -t ossfuzz/base-libfuzzer base-libfuzzer" + + stage name: 'ossfuzz/base-runner', concurrency: 1 + sh "docker build $dockerOptions -t ossfuzz/base-runner base-runner" + + stage name: 'ossfuzz/libfuzzer-runner', concurrency: 1 + sh "docker build $dockerOptions -t ossfuzz/libfuzzer-runner libfuzzer-runner" + } } diff --git a/infra/base-images/all.sh b/infra/base-images/all.sh index 39f563887..d6631cbba 100755 --- a/infra/base-images/all.sh +++ b/infra/base-images/all.sh @@ -18,4 +18,5 @@ docker build --pull -t ossfuzz/base $@ infra/base-images/base docker build -t ossfuzz/base-clang $@ infra/base-images/base-clang docker build -t ossfuzz/base-libfuzzer $@ infra/base-images/base-libfuzzer +docker build -t ossfuzz/base-runner $@ infra/base-images/base-runner docker build -t ossfuzz/libfuzzer-runner $@ infra/base-images/libfuzzer-runner diff --git a/infra/base-images/base-runner/Dockerfile b/infra/base-images/base-runner/Dockerfile new file mode 100644 index 000000000..666cc3366 --- /dev/null +++ b/infra/base-images/base-runner/Dockerfile @@ -0,0 +1,20 @@ +# Copyright 2016 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. +# +################################################################################ + +FROM ossfuzz/base +MAINTAINER mike.aizatsky@gmail.com +COPY test_all run_fuzzer /usr/local/bin/ + diff --git a/infra/base-images/base-runner/run_fuzzer b/infra/base-images/base-runner/run_fuzzer new file mode 100755 index 000000000..630d22e7a --- /dev/null +++ b/infra/base-images/base-runner/run_fuzzer @@ -0,0 +1,41 @@ +#!/bin/bash -eu +# Copyright 2016 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. +# +################################################################################ + +# Fuzzer runner. Appends .options arguments and seed corpus to users args. +# Usage: $0 + +cd $OUT + +FUZZER=$1 +shift +CMD_LINE="$FUZZER $@" + +OPTIONS_FILE="${FUZZER}.options" +if [ -f $OPTIONS_FILE ]; then + OPTIONS_ARGS=$(grep "=" $OPTIONS_FILE | sed 's/\(\w*\)\W*=\W*\(.*\)/-\1=\2 /g' | tr '\n' ' ') + CMD_LINE="$CMD_LINE $OPTIONS_ARGS" +fi + +SEED_CORPUS="${FUZZER}_seed_corpus.zip" +if [ -f $SEED_CORPUS ]; then + rm -rf /tmp/seed_corpus/ && mkdir /tmp/seed_corpus/ + unzip -d /tmp/seed_corpus/ $SEED_CORPUS + CMD_LINE="$CMD_LINE /tmp/seed_corpus/" +fi + +echo $CMD_LINE +bash -c "$CMD_LINE" diff --git a/infra/base-images/base-runner/test_all b/infra/base-images/base-runner/test_all new file mode 100755 index 000000000..670f93a1b --- /dev/null +++ b/infra/base-images/base-runner/test_all @@ -0,0 +1,53 @@ +#!/bin/bash -eu +# Copyright 2016 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. +# +################################################################################ + +# Test fuzzers + +REPORT_DIR="/junit_reports" +mkdir -p $REPORT_DIR + +set -o pipefail + +N=0 +for FUZZER_BINARY in $(find $OUT/ -executable -type f); do + FUZZER=$(basename $FUZZER_BINARY) + echo "testing $FUZZER" + out=$(tempfile) + run_fuzzer $FUZZER -runs=32 | tee $out + N=$[$N+1] + + REPORT_TEXT=$(cat <<-EOF + + + + + + + +EOF +) + echo $REPORT_TEXT > /junit_reports/$FUZZER.xml +done + +if [ "$N" -eq "0" ]; then + echo "ERROR: no fuzzers found in $OUT/" + ls -al $OUT + exit 1 +fi + +echo "$N fuzzers total" + diff --git a/infra/push-images/Jenkinsfile b/infra/push-images/Jenkinsfile index 9d294da00..69183a24d 100644 --- a/infra/push-images/Jenkinsfile +++ b/infra/push-images/Jenkinsfile @@ -17,7 +17,7 @@ // Jenkins build script to push docker images to docker repository. def images = ['ossfuzz/base', 'ossfuzz/base-clang', 'ossfuzz/base-libfuzzer', - 'ossfuzz/libfuzzer-runner'] + 'ossfuzz/base-runner', 'ossfuzz/libfuzzer-runner'] node() { docker.withRegistry('', 'docker-login') {