Skip to content

Commit 7d244bf

Browse files
tmlemanlgirdwood
authored andcommitted
scripts: fuzz: add optional libFuzzer dictionary (-d) option
Add a -d <dfile> option to fuzz.sh that forwards -dict=<dfile> to the libFuzzer executable. A dictionary of known IPC command dwords and enum constants helps the mutator reach deeper dispatch paths that random mutation rarely hits. The option is deliberately non-fatal: a missing or empty dictionary file only emits a warning and the fuzzer runs without it. The dictionary is a pure enhancement and must never block a fuzzing run, for example when its generator fails after an unrelated header change in CI. fuzz.sh stays agnostic of how the dictionary is produced. The caller is responsible for generating and passing the file. Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
1 parent d9f9ba1 commit 7d244bf

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

scripts/fuzz.sh

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Usage:
2121
-j n Number of concurrent -jobs=n. Defaults to 1.
2222
The value 0 uses the output of the 'nproc' command.
2323
-a arch The architecture to build against (i386, x86_64)
24+
-d dfile Pass -dict=dfile to libFuzzer. A missing or empty dfile
25+
is a non-fatal warning: the fuzzer then runs without it.
2426
2527
Arguments after -- are passed as is to CMake (through west).
2628
When passing conflicting -DVAR='VAL UE1' -DVAR='VAL UE2' to CMake,
@@ -93,9 +95,10 @@ main()
9395
local ARCH=i386
9496
local IPC
9597
local BOARD
98+
local DICT
9699

97100
# Parse "$@". getopts stops after '--'
98-
while getopts "i:hj:ps:a:o:t:b" opt; do
101+
while getopts "i:hj:ps:a:o:t:bd:" opt; do
99102
case "$opt" in
100103
i) IPC="$OPTARG";;
101104
h) print_help; exit 0;;
@@ -105,6 +108,7 @@ main()
105108
o) FUZZER_STDOUT="$OPTARG";;
106109
t) TEST_DURATION="$OPTARG";;
107110
a) ARCH="$OPTARG";;
111+
d) DICT="$OPTARG";;
108112
b) BUILD_ONLY=true;;
109113
*) print_help; exit 1;;
110114
esac
@@ -169,11 +173,23 @@ main()
169173
jobs_opts+=( -jobs="$JOBS" -close_fd_mask=1 )
170174
fi
171175

176+
# Optional libFuzzer dictionary (-d). An absent or empty file is a
177+
# non-fatal warning: the dictionary is a pure enhancement and must
178+
# never block a fuzzing run (e.g. when its generator fails in CI).
179+
local dict_opts=( )
180+
if [ -n "$DICT" ]; then
181+
if [ -s "$DICT" ]; then
182+
dict_opts+=( -dict="$DICT" )
183+
else
184+
>&2 printf 'WARN: dictionary %s missing or empty; running without it\n' "$DICT"
185+
fi
186+
fi
187+
172188
date
173189
# Help is at: -help=1
174190
( set -x
175191
>"$FUZZER_STDOUT" build-fuzz/zephyr/zephyr.exe -max_total_time="$TEST_DURATION" \
176-
-verbosity=0 "${jobs_opts[@]}" ./fuzz_corpus ) || {
192+
-verbosity=0 "${jobs_opts[@]}" "${dict_opts[@]}" ./fuzz_corpus ) || {
177193
ret=$?
178194
>&2 printf 'zephyr.exe returned: %d\n' $ret
179195
date

0 commit comments

Comments
 (0)