@@ -21,9 +21,7 @@ GOPATH="${GOPATH:-/root/go}"
21
21
GO_SRC=" ${GOPATH} /src"
22
22
PROJECT_PATH=" github.com/fluxcd/source-controller"
23
23
24
- cd " ${GO_SRC} "
25
-
26
- pushd " ${PROJECT_PATH} "
24
+ pushd " ${GO_SRC} /${PROJECT_PATH} "
27
25
28
26
export TARGET_DIR=" $( /bin/pwd) /build/libgit2/${LIBGIT2_TAG} "
29
27
@@ -58,9 +56,7 @@ export CGO_LDFLAGS="$(pkg-config --libs --static --cflags libssh2 openssl libgit
58
56
59
57
go mod tidy -compat=1.17
60
58
61
- popd
62
-
63
- pushd " ${PROJECT_PATH} /tests/fuzz"
59
+ pushd " tests/fuzz"
64
60
65
61
# Setup files to be embedded into controllers_fuzzer.go's testFiles variable.
66
62
mkdir -p testdata/crd
@@ -69,28 +65,31 @@ cp -r ../../controllers/testdata/certs testdata/
69
65
70
66
go mod tidy -compat=1.17
71
67
72
- # ref: https://github.com/google/oss-fuzz/blob/master/infra/base-images/base-builder/compile_go_fuzzer
73
- go-fuzz -tags gofuzz -func=FuzzRandomGitFiles -o gitrepository_fuzzer.a .
74
- clang -o /out/fuzz_random_git_files \
75
- gitrepository_fuzzer.a \
76
- " ${TARGET_DIR} /lib/libgit2.a" \
77
- " ${TARGET_DIR} /lib/libssh2.a" \
78
- " ${TARGET_DIR} /lib/libz.a" \
79
- " ${TARGET_DIR} /lib64/libssl.a" \
80
- " ${TARGET_DIR} /lib64/libcrypto.a" \
81
- -fsanitize=fuzzer
82
-
83
- go-fuzz -tags gofuzz -func=FuzzGitResourceObject -o fuzz_git_resource_object.a .
84
- clang -o /out/fuzz_git_resource_object \
85
- fuzz_git_resource_object.a \
86
- " ${TARGET_DIR} /lib/libgit2.a" \
87
- " ${TARGET_DIR} /lib/libssh2.a" \
88
- " ${TARGET_DIR} /lib/libz.a" \
89
- " ${TARGET_DIR} /lib64/libssl.a" \
90
- " ${TARGET_DIR} /lib64/libcrypto.a" \
91
- -fsanitize=fuzzer
68
+ # Using compile_go_fuzzer to compile fails when statically linking libgit2 dependencies
69
+ # via CFLAGS/CXXFLAGS.
70
+ function go_compile(){
71
+ function=$1
72
+ fuzzer=$2
73
+
74
+ if [[ $SANITIZER = * coverage* ]]; then
75
+ # ref: https://github.com/google/oss-fuzz/blob/master/infra/base-images/base-builder/compile_go_fuzzer
76
+ compile_go_fuzzer " ${PROJECT_PATH} /tests/fuzz" " ${function} " " ${fuzzer} "
77
+ else
78
+ go-fuzz -tags gofuzz -func=" ${function} " -o " ${fuzzer} .a" .
79
+ ${CXX} ${CXXFLAGS} ${LIB_FUZZING_ENGINE} -o " ${OUT} /${fuzzer} " \
80
+ " ${fuzzer} .a" \
81
+ " ${TARGET_DIR} /lib/libgit2.a" " ${TARGET_DIR} /lib/libssh2.a" \
82
+ " ${TARGET_DIR} /lib/libz.a" " ${TARGET_DIR} /lib64/libssl.a" \
83
+ " ${TARGET_DIR} /lib64/libcrypto.a" \
84
+ -fsanitize=" ${SANITIZER} "
85
+ fi
86
+ }
87
+
88
+ go_compile FuzzRandomGitFiles fuzz_gitrepository_fuzzer
89
+ go_compile FuzzGitResourceObject fuzz_git_resource_object
92
90
93
91
# By now testdata is embedded in the binaries and no longer needed.
94
92
rm -rf testdata/
95
93
96
94
popd
95
+ popd
0 commit comments