Skip to content

Commit 9869e02

Browse files
committed
Merge branch 'js/oss-fuzz-build-in-ci'
oss-fuzz tests are built and run in CI. * js/oss-fuzz-build-in-ci: ci: build and run minimal fuzzers in GitHub CI fuzz: fix fuzz test build rules
2 parents 68812df + c4a9cf1 commit 9869e02

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,17 @@ jobs:
309309
with:
310310
name: failed-tests-${{matrix.vector.jobname}}
311311
path: ${{env.FAILED_TEST_ARTIFACTS}}
312+
fuzz-smoke-test:
313+
name: fuzz smoke test
314+
needs: ci-config
315+
if: needs.ci-config.outputs.enabled == 'yes'
316+
env:
317+
CC: clang
318+
runs-on: ubuntu-latest
319+
steps:
320+
- uses: actions/checkout@v3
321+
- run: ci/install-dependencies.sh
322+
- run: ci/run-build-and-minimal-fuzzers.sh
312323
dockerized:
313324
name: ${{matrix.vector.jobname}} (${{matrix.vector.image}})
314325
needs: ci-config

Makefile

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,10 @@ SCRIPTS = $(SCRIPT_SH_GEN) \
752752

753753
ETAGS_TARGET = TAGS
754754

755+
# If you add a new fuzzer, please also make sure to run it in
756+
# ci/run-build-and-minimal-fuzzers.sh so that we make sure it still links and
757+
# runs in the future.
758+
FUZZ_OBJS += oss-fuzz/dummy-cmd-main.o
755759
FUZZ_OBJS += oss-fuzz/fuzz-commit-graph.o
756760
FUZZ_OBJS += oss-fuzz/fuzz-date.o
757761
FUZZ_OBJS += oss-fuzz/fuzz-pack-headers.o
@@ -762,7 +766,7 @@ fuzz-objs: $(FUZZ_OBJS)
762766
# Always build fuzz objects even if not testing, to prevent bit-rot.
763767
all:: $(FUZZ_OBJS)
764768

765-
FUZZ_PROGRAMS += $(patsubst %.o,%,$(FUZZ_OBJS))
769+
FUZZ_PROGRAMS += $(patsubst %.o,%,$(filter-out %dummy-cmd-main.o,$(FUZZ_OBJS)))
766770

767771
# Empty...
768772
EXTRA_PROGRAMS =
@@ -3850,16 +3854,17 @@ cover_db_html: cover_db
38503854
#
38513855
# make CC=clang CXX=clang++ \
38523856
# CFLAGS="-fsanitize=fuzzer-no-link,address" \
3853-
# LIB_FUZZING_ENGINE="-fsanitize=fuzzer" \
3857+
# LIB_FUZZING_ENGINE="-fsanitize=fuzzer,address" \
38543858
# fuzz-all
38553859
#
3856-
FUZZ_CXXFLAGS ?= $(CFLAGS)
3860+
FUZZ_CXXFLAGS ?= $(ALL_CFLAGS)
38573861

38583862
.PHONY: fuzz-all
38593863

3860-
$(FUZZ_PROGRAMS): all
3861-
$(QUIET_LINK)$(CXX) $(FUZZ_CXXFLAGS) $(LIB_OBJS) $(BUILTIN_OBJS) \
3862-
$(XDIFF_OBJS) $(EXTLIBS) git.o $@.o $(LIB_FUZZING_ENGINE) -o $@
3864+
$(FUZZ_PROGRAMS): %: %.o oss-fuzz/dummy-cmd-main.o $(GITLIBS) GIT-LDFLAGS
3865+
$(QUIET_LINK)$(CXX) $(FUZZ_CXXFLAGS) -o $@ $(ALL_LDFLAGS) \
3866+
-Wl,--allow-multiple-definition \
3867+
$(filter %.o,$^) $(filter %.a,$^) $(LIBS) $(LIB_FUZZING_ENGINE)
38633868

38643869
fuzz-all: $(FUZZ_PROGRAMS)
38653870

ci/run-build-and-minimal-fuzzers.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
#
3+
# Build and test Git's fuzzers
4+
#
5+
6+
. ${0%/*}/lib.sh
7+
8+
group "Build fuzzers" make \
9+
CC=clang \
10+
CXX=clang++ \
11+
CFLAGS="-fsanitize=fuzzer-no-link,address" \
12+
LIB_FUZZING_ENGINE="-fsanitize=fuzzer,address" \
13+
fuzz-all
14+
15+
for fuzzer in commit-graph date pack-headers pack-idx ; do
16+
begin_group "fuzz-$fuzzer"
17+
./oss-fuzz/fuzz-$fuzzer -verbosity=0 -runs=1 || exit 1
18+
end_group "fuzz-$fuzzer"
19+
done

oss-fuzz/dummy-cmd-main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "git-compat-util.h"
2+
3+
/*
4+
* When linking the fuzzers, we link against common-main.o to pick up some
5+
* symbols. However, even though we ignore common-main:main(), we still need to
6+
* provide all the symbols it references. In the fuzzers' case, we need to
7+
* provide a dummy cmd_main() for the linker to be happy. It will never be
8+
* executed.
9+
*/
10+
11+
int cmd_main(int argc, const char **argv) {
12+
BUG("We should not execute cmd_main() from a fuzz target");
13+
return 1;
14+
}

0 commit comments

Comments
 (0)