Skip to content

Commit 2a4ed19

Browse files
authored
Merge pull request #777 from pjbgf/improv-fuzz
fuzz: Use build script from upstream and fix fuzzers
2 parents f971376 + f73957b commit 2a4ed19

6 files changed

Lines changed: 34 additions & 90 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ require (
202202
github.com/prometheus/procfs v0.8.0 // indirect
203203
github.com/russross/blackfriday v1.6.0 // indirect
204204
github.com/ryanuber/go-glob v1.0.0 // indirect
205-
github.com/sirupsen/logrus v1.8.1 // indirect
205+
github.com/sirupsen/logrus v1.9.0 // indirect
206206
github.com/spf13/cobra v1.6.1 // indirect
207207
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
208208
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect

go.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,9 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
591591
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
592592
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
593593
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
594-
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
595594
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
595+
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
596+
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
596597
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
597598
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
598599
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=

tests/fuzz/Dockerfile.builder

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
FROM gcr.io/oss-fuzz-base/base-builder-go
22

3-
COPY ./ $GOPATH/src/github.com/fluxcd/kustomize-controller/
4-
COPY ./tests/fuzz/oss_fuzz_build.sh $SRC/build.sh
3+
ENV SRC=$GOPATH/src/github.com/fluxcd/kustomize-controller
4+
ENV FLUX_CI=true
5+
6+
COPY ./ $SRC
7+
RUN wget https://raw.githubusercontent.com/google/oss-fuzz/master/projects/fluxcd/build.sh -O $SRC/build.sh
58

69
WORKDIR $SRC

tests/fuzz/README.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ open source projects.
66
The long running fuzzing execution is configured in the [oss-fuzz repository].
77
Shorter executions are done on a per-PR basis, configured as a [github workflow].
88

9-
For fuzzers to be called, they must be compiled within [oss_fuzz_build.sh](./oss_fuzz_build.sh).
10-
119
### Testing locally
1210

1311
Build fuzzers:
@@ -19,12 +17,12 @@ All fuzzers will be built into `./build/fuzz/out`.
1917

2018
Smoke test fuzzers:
2119

20+
All the fuzzers will be built and executed once, to ensure they are fully functional.
21+
2222
```bash
2323
make fuzz-smoketest
2424
```
2525

26-
The smoke test runs each fuzzer once to ensure they are fully functional.
27-
2826
Run fuzzer locally:
2927
```bash
3028
./build/fuzz/out/fuzz_conditions_match
@@ -39,6 +37,27 @@ Run fuzzer inside a container:
3937
/out/fuzz_conditions_match
4038
```
4139

40+
### Caveats of creating oss-fuzz compatible tests
41+
42+
#### Segregate fuzz tests
43+
44+
OSS-Fuzz does not properly support mixed `*_test.go` files, in which there is a combination
45+
of fuzz and non-fuzz tests. To mitigate this problem, ensure your fuzz tests are not in the
46+
same file as other Go tests. As a pattern, call your fuzz test files `*_fuzz_test.go`.
47+
48+
#### Build tags to avoid conflicts when running Go tests
49+
50+
Due to the issue above, code duplication will occur when creating fuzz tests that rely on
51+
helper functions that are shared with other tests. To avoid build issues, add a conditional
52+
build tag at the top of the `*_fuzz_test.go` file:
53+
```go
54+
//go:build gofuzz_libfuzzer
55+
// +build gofuzz_libfuzzer
56+
```
57+
58+
The build tag above is set at [go-118-fuzz-build].
59+
At this point in time we can't pass on specific tags from [compile_native_go_fuzzer].
60+
4261
### Running oss-fuzz locally
4362

4463
The `make fuzz-smoketest` is meant to be an easy way to reproduce errors that may occur
@@ -59,3 +78,5 @@ For latest info on testing oss-fuzz locally, refer to the [upstream guide].
5978
[oss-fuzz repository]: https://github.com/google/oss-fuzz/tree/master/projects/fluxcd
6079
[github workflow]: .github/workflows/cifuzz.yaml
6180
[upstream guide]: https://google.github.io/oss-fuzz/getting-started/new-project-guide/#testing-locally
81+
[go-118-fuzz-build]: https://github.com/AdamKorcz/go-118-fuzz-build/blob/b2031950a318d4f2dcf3ec3e128f904d5cf84623/main.go#L40
82+
[compile_native_go_fuzzer]: https://github.com/google/oss-fuzz/blob/c2d827cb78529fdc757c9b0b4fea0f1238a54814/infra/base-images/base-builder/compile_native_go_fuzzer#L32

tests/fuzz/oss_fuzz_build.sh

Lines changed: 0 additions & 81 deletions
This file was deleted.

tests/fuzz/oss_fuzz_run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
set -euxo pipefail
1818

1919
# run each fuzzer once to ensure they are working properly
20-
find /out -type f -name "fuzz*" -exec echo {} -runs=1 \; | bash -e
20+
find /out -type f -iname "fuzz*" -exec echo {} -runs=1 \; | bash -e

0 commit comments

Comments
 (0)