Skip to content

Commit ae7c00a

Browse files
author
Paulo Gomes
committed
fuzz: Refactor Fuzzers based on Go native fuzzing
The existing fuzzers were converted into the Go native format. Based on how the code was structured on this project, the fuzzers can be quite effective, allowing for entire E2E fuzzing in some cases, but with very low execution cost. The previous controller fuzzer was converted but will need to be refactored once the controller has been rewritten. Note that due to the libgit2 dependencies a copy of compile_native_go_fuzzer had to be made and modified so that we can inject libgit2 during the linking process. Signed-off-by: Paulo Gomes <[email protected]>
1 parent a7435ed commit ae7c00a

File tree

10 files changed

+554
-379
lines changed

10 files changed

+554
-379
lines changed

Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ BUILD_DIR := $(REPOSITORY_ROOT)/build
3737
# Other dependency versions
3838
ENVTEST_BIN_VERSION ?= 1.19.2
3939

40+
# FUZZ_TIME defines the max amount of time, in Go Duration,
41+
# each fuzzer should run for.
42+
FUZZ_TIME ?= 1m
43+
4044
# Caches libgit2 versions per tag, "forcing" rebuild only when needed.
4145
LIBGIT2_PATH := $(BUILD_DIR)/libgit2/$(LIBGIT2_TAG)
4246
LIBGIT2_LIB_PATH := $(LIBGIT2_PATH)/lib
@@ -219,7 +223,7 @@ ENVTEST = $(GOBIN)/setup-envtest
219223
setup-envtest: ## Download envtest-setup locally if necessary.
220224
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
221225

222-
# Build fuzzers
226+
# Build fuzzers used by oss-fuzz.
223227
fuzz-build: $(LIBGIT2)
224228
rm -rf $(shell pwd)/build/fuzz/
225229
mkdir -p $(shell pwd)/build/fuzz/out/
@@ -231,13 +235,20 @@ fuzz-build: $(LIBGIT2)
231235
-v "$(shell pwd)/build/fuzz/out":/out \
232236
local-fuzzing:latest
233237

238+
# Run each fuzzer once to ensure they will work when executed by oss-fuzz.
234239
fuzz-smoketest: fuzz-build
235240
docker run --rm \
236241
-v "$(shell pwd)/build/fuzz/out":/out \
237242
-v "$(shell pwd)/tests/fuzz/oss_fuzz_run.sh":/runner.sh \
238243
local-fuzzing:latest \
239244
bash -c "/runner.sh"
240245

246+
# Run fuzz tests for the duration set in FUZZ_TIME.
247+
fuzz-native:
248+
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) \
249+
FUZZ_TIME=$(FUZZ_TIME) \
250+
./tests/fuzz/native_go_run.sh
251+
241252
# go-install-tool will 'go install' any package $2 and install it to $1.
242253
define go-install-tool
243254
@[ -f $(1) ] || { \

0 commit comments

Comments
 (0)