aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Catena cyber <35799796+catenacyber@users.noreply.github.com>2020-11-21 16:11:43 +0100
committerGravatar GitHub <noreply@github.com>2020-11-21 07:11:43 -0800
commit2db56c41743333db03e811b6687dca05620210d5 (patch)
treefc2d2ba21d3f39915216ac9158238236922b071b
parente534f4fecc7c0992b105a79123ec97bb55ae2396 (diff)
Golang project uses compile_go_fuzzer script (#4685)
* Golang project uses compile_go_fuzzer script * Kubernetes project uses compile_go_fuzzer script * Adds golang to ci covergae builds * fixup * Golang coverage with go modules cf coredns project
-rwxr-xr-xinfra/base-images/base-builder/compile_go_fuzzer8
-rwxr-xr-xinfra/ci/build.py2
-rw-r--r--infra/ci/build_test.py4
-rw-r--r--projects/go-coredns/Dockerfile3
-rwxr-xr-xprojects/go-coredns/build.sh6
-rwxr-xr-xprojects/golang/build.sh2
-rwxr-xr-xprojects/kubernetes/build.sh2
7 files changed, 17 insertions, 10 deletions
diff --git a/infra/base-images/base-builder/compile_go_fuzzer b/infra/base-images/base-builder/compile_go_fuzzer
index 5fc8b70f..c6cc3dd8 100755
--- a/infra/base-images/base-builder/compile_go_fuzzer
+++ b/infra/base-images/base-builder/compile_go_fuzzer
@@ -24,7 +24,13 @@ if [[ $# -eq 4 ]]; then
fi
if [[ $SANITIZER = *coverage* ]]; then
- cd $GOPATH/src/$path
+ if [[ $GO111MODULE = on ]]; then
+ basemod=`echo $path | cut -d/ -f1-3`
+ cd $GOPATH/pkg/mod/`go list -m $basemod | sed 's/ /@/'`
+ cd ./`echo $path | cut -d/ -f4-`
+ else
+ cd $GOPATH/src/$path
+ fi
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
diff --git a/infra/ci/build.py b/infra/ci/build.py
index 67a97587..a1a22836 100755
--- a/infra/ci/build.py
+++ b/infra/ci/build.py
@@ -32,7 +32,7 @@ DEFAULT_ENGINES = ['afl', 'honggfuzz', 'libfuzzer']
DEFAULT_SANITIZERS = ['address', 'undefined']
# Languages from project.yaml that have code coverage support.
-LANGUAGES_WITH_COVERAGE_SUPPORT = ['c', 'c++']
+LANGUAGES_WITH_COVERAGE_SUPPORT = ['c', 'c++', 'go']
def get_changed_files():
diff --git a/infra/ci/build_test.py b/infra/ci/build_test.py
index ef2d3a80..59fa3cf5 100644
--- a/infra/ci/build_test.py
+++ b/infra/ci/build_test.py
@@ -73,11 +73,11 @@ class TestShouldBuild(unittest.TestCase):
self.assertTrue(build.should_build(project_yaml))
def test_go_coverage_build(self):
- """Tests that should_build returns False for coverage build of a project
+ """Tests that should_build returns True for coverage build of a project
specifying 'libfuzzer' and for fuzzing_engines."""
_set_coverage_build()
project_yaml = {'language': 'go'}
- self.assertFalse(build.should_build(project_yaml))
+ self.assertTrue(build.should_build(project_yaml))
def test_engine_project_none_build(self):
"""Tests that should_build returns False for an engine: 'none' build when
diff --git a/projects/go-coredns/Dockerfile b/projects/go-coredns/Dockerfile
index f77a4629..824e6d8f 100644
--- a/projects/go-coredns/Dockerfile
+++ b/projects/go-coredns/Dockerfile
@@ -15,7 +15,8 @@
################################################################################
FROM gcr.io/oss-fuzz-base/base-builder
-RUN git clone --depth 1 https://github.com/coredns/coredns coredns
+ENV GO111MODULE=on
+RUN go get github.com/coredns/coredns
COPY build.sh $SRC/
WORKDIR $SRC/
diff --git a/projects/go-coredns/build.sh b/projects/go-coredns/build.sh
index d1d021b7..16b10cae 100755
--- a/projects/go-coredns/build.sh
+++ b/projects/go-coredns/build.sh
@@ -17,13 +17,13 @@
# Same as usual except for added -tags gofuzz.
+cd $GOPATH/pkg/mod/`go list -m github.com/coredns/coredns | sed 's/ /@/'`
-cd coredns
#make
ls plugin/*/fuzz.go | while read target
do
fuzzed_plugin=`echo $target | cut -d'/' -f 2`
- compile_go_fuzzer github.com/coredns/coredns/plugin/$fuzzed_plugin Fuzz fuzz_plugin_$fuzzed_plugin
+ compile_go_fuzzer github.com/coredns/coredns/plugin/$fuzzed_plugin Fuzz fuzz_plugin_$fuzzed_plugin gofuzz
done
-compile_go_fuzzer github.com/coredns/coredns/test Fuzz fuzz_core
+compile_go_fuzzer github.com/coredns/coredns/test Fuzz fuzz_core gofuzz
diff --git a/projects/golang/build.sh b/projects/golang/build.sh
index 70972fa4..064378aa 100755
--- a/projects/golang/build.sh
+++ b/projects/golang/build.sh
@@ -15,7 +15,7 @@
function compile_fuzzer {
fuzzer=$(basename $1)
- compile_fuzzer "github.com/dvyukov/go-fuzz-corpus/$fuzzer" Fuzz $fuzzer
+ compile_go_fuzzer "github.com/dvyukov/go-fuzz-corpus/$fuzzer" Fuzz $fuzzer
# Pack the seed corpus
zip -r $OUT/fuzzer-${fuzzer}_seed_corpus.zip \
diff --git a/projects/kubernetes/build.sh b/projects/kubernetes/build.sh
index 4e6bded1..3b331ae9 100755
--- a/projects/kubernetes/build.sh
+++ b/projects/kubernetes/build.sh
@@ -25,7 +25,7 @@ function compile_fuzzer {
local function=$2
local fuzzer="${pkg}_${function}"
- compile_fuzzer "k8s.io/kubernetes/test/fuzz/${pkg}" $function $fuzzer
+ compile_go_fuzzer "k8s.io/kubernetes/test/fuzz/${pkg}" $function $fuzzer
}
compile_fuzzer "yaml" "FuzzDurationStrict"