-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #536 from pjbgf/fuzz
Refactor Fuzz implementation
- Loading branch information
Showing
12 changed files
with
734 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: CIFuzz | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
jobs: | ||
Fuzzing: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Restore Go cache | ||
uses: actions/cache@v1 | ||
with: | ||
path: /home/runner/work/_temp/_github_home/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Smoke test Fuzzers | ||
run: make fuzz-smoketest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM gcr.io/oss-fuzz-base/base-builder-go | ||
|
||
COPY ./ $GOPATH/src/github.com/fluxcd/kustomize-controller/ | ||
COPY ./tests/fuzz/oss_fuzz_build.sh $SRC/build.sh | ||
|
||
WORKDIR $SRC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# fuzz testing | ||
|
||
Flux is part of Google's [oss fuzz] program which provides continuous fuzzing for | ||
open source projects. | ||
|
||
The long running fuzzing execution is configured in the [oss-fuzz repository]. | ||
Shorter executions are done on a per-PR basis, configured as a [github workflow]. | ||
|
||
For fuzzers to be called, they must be compiled within [oss_fuzz_build.sh](./oss_fuzz_build.sh). | ||
|
||
### Testing locally | ||
|
||
Build fuzzers: | ||
|
||
```bash | ||
make fuzz-build | ||
``` | ||
All fuzzers will be built into `./build/fuzz/out`. | ||
|
||
Smoke test fuzzers: | ||
|
||
```bash | ||
make fuzz-smoketest | ||
``` | ||
|
||
The smoke test runs each fuzzer once to ensure they are fully functional. | ||
|
||
Run fuzzer locally: | ||
```bash | ||
./build/fuzz/out/fuzz_conditions_match | ||
``` | ||
|
||
Run fuzzer inside a container: | ||
|
||
```bash | ||
docker run --rm -ti \ | ||
-v "$(pwd)/build/fuzz/out":/out \ | ||
gcr.io/oss-fuzz/fluxcd \ | ||
/out/fuzz_conditions_match | ||
``` | ||
|
||
|
||
[oss fuzz]: https://github.com/google/oss-fuzz | ||
[oss-fuzz repository]: https://github.com/google/oss-fuzz/tree/master/projects/fluxcd | ||
[github workflow]: .github/workflows/cifuzz.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//go:build gofuzz | ||
// +build gofuzz | ||
|
||
/* | ||
Copyright 2022 The Flux authors | ||
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. | ||
*/ | ||
|
||
package age | ||
|
||
import ( | ||
fuzz "github.com/AdaLogics/go-fuzz-headers" | ||
) | ||
|
||
// FuzzAge implements a fuzzer that targets functions within age/keysource.go. | ||
func FuzzAge(data []byte) int { | ||
f := fuzz.NewConsumer(data) | ||
masterKey := MasterKey{} | ||
|
||
if err := f.GenerateStruct(&masterKey); err != nil { | ||
return 0 | ||
} | ||
|
||
_ = masterKey.Encrypt(data) | ||
_ = masterKey.EncryptIfNeeded(data) | ||
|
||
receipts, err := f.GetString() | ||
if err != nil { | ||
return 0 | ||
} | ||
|
||
_, _ = MasterKeysFromRecipients(receipts) | ||
_, _ = MasterKeyFromRecipient(receipts) | ||
|
||
return 1 | ||
} |
Oops, something went wrong.