aboutsummaryrefslogtreecommitdiff
path: root/infra/base-images/base-builder
diff options
context:
space:
mode:
authorCatena cyber <35799796+catenacyber@users.noreply.github.com>2020-11-19 23:18:25 +0100
committerGitHub <noreply@github.com>2020-11-19 14:18:25 -0800
commit217175212ba1d484017c32fe6518f85c1aa1273f (patch)
treebf48c327c2cd39c6fd02f1469190c90b2f2ed5ec /infra/base-images/base-builder
parent772d0efef58adee26223efeac80a9c8c44de496a (diff)
downloadoss-fuzz-217175212ba1d484017c32fe6518f85c1aa1273f.tar.gz
[infra] Use generic compile_go_fuzzer for golang projects (#4659)
* Use generic compile_go_fuzzer for golang projects * fix the copyright in the new script Co-authored-by: Max Moroz <mmoroz@chromium.org>
Diffstat (limited to 'infra/base-images/base-builder')
-rw-r--r--infra/base-images/base-builder/Dockerfile2
-rwxr-xr-xinfra/base-images/base-builder/compile_go_fuzzer47
2 files changed, 48 insertions, 1 deletions
diff --git a/infra/base-images/base-builder/Dockerfile b/infra/base-images/base-builder/Dockerfile
index c03543eed..a394db7e5 100644
--- a/infra/base-images/base-builder/Dockerfile
+++ b/infra/base-images/base-builder/Dockerfile
@@ -151,7 +151,7 @@ RUN mkdir honggfuzz && \
rm -rf $SRC/oss-fuzz.tar.gz
COPY compile compile_afl compile_dataflow compile_libfuzzer compile_honggfuzz \
- precompile_honggfuzz srcmap write_labels.py /usr/local/bin/
+ compile_go_fuzzer precompile_honggfuzz srcmap write_labels.py /usr/local/bin/
COPY detect_repo.py /opt/cifuzz/
COPY ossfuzz_coverage_runner.go $GOPATH
diff --git a/infra/base-images/base-builder/compile_go_fuzzer b/infra/base-images/base-builder/compile_go_fuzzer
new file mode 100755
index 000000000..5fc8b70f0
--- /dev/null
+++ b/infra/base-images/base-builder/compile_go_fuzzer
@@ -0,0 +1,47 @@
+#!/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.
+#
+################################################################################
+
+path=$1
+function=$2
+fuzzer=$3
+tags=""
+if [[ $# -eq 4 ]]; then
+ tags="-tags $4"
+fi
+
+if [[ $SANITIZER = *coverage* ]]; then
+ cd $GOPATH/src/$path
+ fuzzed_package=`pwd | rev | cut -d'/' -f 1 | rev`
+ cp $GOPATH/ossfuzz_coverage_runner.go ./"${function,,}"_test.go
+ sed -i -e 's/FuzzFunction/'$function'/' ./"${function,,}"_test.go
+ sed -i -e 's/mypackagebeingfuzzed/'$fuzzed_package'/' ./"${function,,}"_test.go
+ sed -i -e 's/TestFuzzCorpus/Test'$function'Corpus/' ./"${function,,}"_test.go
+
+ echo "#/bin/sh" > $OUT/$fuzzer
+ echo "cd $path" >> $OUT/$fuzzer
+ echo "go test -run Test${function}Corpus -v $tags -coverprofile \$1 " >> $OUT/$fuzzer
+ chmod +x $OUT/$fuzzer
+
+ cd -
+else
+ # Compile and instrument all Go files relevant to this fuzz target.
+ echo "Running go-fuzz $tags -func $function -o $fuzzer.a $path"
+ go-fuzz $tags -func $function -o $fuzzer.a $path
+
+ # Link Go code ($fuzzer.a) with fuzzing engine to produce fuzz target binary.
+ $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o $OUT/$fuzzer
+fi