Skip to content

Commit 8422b9a

Browse files
committed
test/cli/fuzz_test.py: added test for fuzzing crashes with C code
1 parent f9b73ed commit 8422b9a

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

oss-fuzz/Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ preprare-samples:
124124

125125
do-fuzz: oss-fuzz-client preprare-samples
126126
mkdir -p corpus
127-
./oss-fuzz-client -only_ascii=1 -timeout=5 -detect_leaks=0 corpus samples ../test/cli/fuzz-crash ../test/cli/fuzz-timeout
127+
./oss-fuzz-client -only_ascii=1 -timeout=5 -detect_leaks=0 corpus samples ../test/cli/fuzz-crash ../test/cli/fuzz-crash_c ../test/cli/fuzz-timeout
128128

129129
dedup-corpus: oss-fuzz-client preprare-samples
130130
mv corpus corpus_
131131
mkdir -p corpus
132-
./oss-fuzz-client -only_ascii=1 -timeout=5 -detect_leaks=0 corpus corpus_ samples ../test/cli/fuzz-crash ../test/cli/fuzz-timeout -merge=1
132+
./oss-fuzz-client -only_ascii=1 -timeout=5 -detect_leaks=0 corpus corpus_ samples ../test/cli/fuzz-crash ../test/cli/fuzz-crash_c ../test/cli/fuzz-timeout -merge=1
133133

134134
# jobs:
135-
# ./oss-fuzz-client -only_ascii=1 -timeout=5 -detect_leaks=0 corpus samples ../test/cli/fuzz-crash ../test/cli/fuzz-timeout -workers=12 -jobs=9
135+
# ./oss-fuzz-client -only_ascii=1 -timeout=5 -detect_leaks=0 corpus samples ../test/cli/fuzz-crash ../test/cli/fuzz-crash_c ../test/cli/fuzz-timeout -workers=12 -jobs=9
136136

137137
# minimize:
138138
# ./oss-fuzz-client -only_ascii=1 -timeout=5 -detect_leaks=0 -minimize_crash=1 crash-0123456789abcdef

test/cli/fuzz_test.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,25 @@ def test_fuzz_crash():
1818
assert failures == {}
1919

2020

21+
def test_fuzz_crash_c():
22+
failures = {}
23+
24+
fuzz_crash_dir = os.path.join(__script_dir, 'fuzz-crash_c')
25+
# TODO: remove check if we have test data
26+
if not os.path.exists(fuzz_crash_dir):
27+
return
28+
for f in os.listdir(fuzz_crash_dir):
29+
ret, stdout, _ = cppcheck(['-q', '--language=c', '--enable=all', '--inconclusive', f], cwd=fuzz_crash_dir)
30+
if ret != 0:
31+
failures[f] = stdout
32+
33+
assert failures == {}
34+
35+
2136
def test_fuzz_timeout():
2237
failures = []
2338

2439
fuzz_timeout_dir = os.path.join(__script_dir, 'fuzz-timeout')
25-
# TODO: remove check if we have test data
26-
if not os.path.exists(fuzz_timeout_dir):
27-
return
2840
for f in os.listdir(fuzz_timeout_dir):
2941
try:
3042
ret, stdout, _ = cppcheck(['-q', '--language=c++', '--enable=all', '--inconclusive', f], cwd=fuzz_timeout_dir, timeout=5)

tools/dmake/dmake.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -376,15 +376,15 @@ static void write_ossfuzz_makefile(std::vector<std::string> libfiles_prio, std::
376376
fout << '\n';
377377
fout << "do-fuzz: oss-fuzz-client preprare-samples\n";
378378
fout << "\tmkdir -p corpus\n";
379-
fout << "\t./oss-fuzz-client -only_ascii=1 -timeout=5 -detect_leaks=0 corpus samples ../test/cli/fuzz-crash ../test/cli/fuzz-timeout\n";
379+
fout << "\t./oss-fuzz-client -only_ascii=1 -timeout=5 -detect_leaks=0 corpus samples ../test/cli/fuzz-crash ../test/cli/fuzz-crash_c ../test/cli/fuzz-timeout\n";
380380
fout << '\n';
381381
fout << "dedup-corpus: oss-fuzz-client preprare-samples\n";
382382
fout << "\tmv corpus corpus_\n";
383383
fout << "\tmkdir -p corpus\n";
384-
fout << "\t./oss-fuzz-client -only_ascii=1 -timeout=5 -detect_leaks=0 corpus corpus_ samples ../test/cli/fuzz-crash ../test/cli/fuzz-timeout -merge=1\n";
384+
fout << "\t./oss-fuzz-client -only_ascii=1 -timeout=5 -detect_leaks=0 corpus corpus_ samples ../test/cli/fuzz-crash ../test/cli/fuzz-crash_c ../test/cli/fuzz-timeout -merge=1\n";
385385
fout << '\n';
386386
fout << "# jobs:\n";
387-
fout << "# ./oss-fuzz-client -only_ascii=1 -timeout=5 -detect_leaks=0 corpus samples ../test/cli/fuzz-crash ../test/cli/fuzz-timeout -workers=12 -jobs=9\n";
387+
fout << "# ./oss-fuzz-client -only_ascii=1 -timeout=5 -detect_leaks=0 corpus samples ../test/cli/fuzz-crash ../test/cli/fuzz-crash_c ../test/cli/fuzz-timeout -workers=12 -jobs=9\n";
388388
fout << '\n';
389389
fout << "# minimize:\n";
390390
fout << "# ./oss-fuzz-client -only_ascii=1 -timeout=5 -detect_leaks=0 -minimize_crash=1 crash-0123456789abcdef\n";

0 commit comments

Comments
 (0)