-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fuzzing: add fuzzing infrastructure in build system
Signed-off-by: Arjun <[email protected]> Reviewed-by: Andrew Clayton <[email protected]> Signed-off-by: Andrew Clayton <[email protected]>
- Loading branch information
1 parent
04a24f6
commit 965fc94
Showing
9 changed files
with
144 additions
and
1 deletion.
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,75 @@ | ||
# Copyright (C) NGINX, Inc. | ||
|
||
|
||
if [ -n "$NXT_FUZZ" ]; then | ||
|
||
# Fuzz-Test object files list. | ||
|
||
$echo "NXT_FUZZ_OBJS = \\" >> $NXT_MAKEFILE | ||
|
||
for nxt_src in $NXT_FUZZ_SRCS | ||
do | ||
nxt_obj=${nxt_src%.c}.o | ||
$echo " $NXT_BUILD_DIR/$nxt_obj \\" >> $NXT_MAKEFILE | ||
done | ||
|
||
|
||
# Fuzz-Test executables. | ||
|
||
cat << END >> $NXT_MAKEFILE | ||
|
||
.PHONY: fuzz | ||
fuzz: $NXT_BUILD_DIR/fuzz_basic \\ | ||
$NXT_BUILD_DIR/fuzz_http_controller \\ | ||
$NXT_BUILD_DIR/fuzz_http_h1p \\ | ||
$NXT_BUILD_DIR/fuzz_http_h1p_peer \\ | ||
$NXT_BUILD_DIR/fuzz_json | ||
|
||
$NXT_BUILD_DIR/fuzz_basic: \$(NXT_FUZZ_OBJS) \\ | ||
$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC | ||
\$(PP_LD) \$@ | ||
\$(v)\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/fuzz_basic \\ | ||
\$(CFLAGS) $NXT_BUILD_DIR/fuzzing/nxt_basic_fuzz.o \\ | ||
$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\ | ||
$NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS \\ | ||
$NXT_FUZZ | ||
|
||
$NXT_BUILD_DIR/fuzz_http_controller: \$(NXT_FUZZ_OBJS) \\ | ||
$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC | ||
\$(PP_LD) \$@ | ||
\$(v)\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/fuzz_http_controller \\ | ||
\$(CFLAGS) $NXT_BUILD_DIR/fuzzing/nxt_http_controller_fuzz.o \\ | ||
$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\ | ||
$NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS \\ | ||
$NXT_FUZZ | ||
|
||
$NXT_BUILD_DIR/fuzz_http_h1p: \$(NXT_FUZZ_OBJS) \\ | ||
$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC | ||
\$(PP_LD) \$@ | ||
\$(v)\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/fuzz_http_h1p \\ | ||
\$(CFLAGS) $NXT_BUILD_DIR/fuzzing/nxt_http_h1p_fuzz.o \\ | ||
$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\ | ||
$NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS \\ | ||
$NXT_FUZZ | ||
|
||
$NXT_BUILD_DIR/fuzz_http_h1p_peer: \$(NXT_FUZZ_OBJS) \\ | ||
$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC | ||
\$(PP_LD) \$@ | ||
\$(v)\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/fuzz_http_h1p_peer \\ | ||
\$(CFLAGS) $NXT_BUILD_DIR/fuzzing/nxt_http_h1p_peer_fuzz.o \\ | ||
$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\ | ||
$NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS \\ | ||
$NXT_FUZZ | ||
|
||
$NXT_BUILD_DIR/fuzz_json: \$(NXT_FUZZ_OBJS) \\ | ||
$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC | ||
\$(PP_LD) \$@ | ||
\$(v)\$(NXT_EXEC_LINK) -o $NXT_BUILD_DIR/fuzz_json \\ | ||
\$(CFLAGS) $NXT_BUILD_DIR/fuzzing/nxt_json_fuzz.o \\ | ||
$NXT_BUILD_DIR/lib/$NXT_LIB_STATIC \\ | ||
$NXT_LD_OPT $NXT_LIBM $NXT_LIBS $NXT_LIB_AUX_LIBS \\ | ||
$NXT_FUZZ | ||
|
||
END | ||
|
||
fi |
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
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,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
export CC=clang | ||
export CXX=clang++ | ||
export CFLAGS="-g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address,undefined -fsanitize=fuzzer-no-link" | ||
export CXXFLAGS="-g -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -fsanitize=address,undefined -fsanitize=fuzzer-no-link" | ||
export LIB_FUZZING_ENGINE="-fsanitize=fuzzer" | ||
|
||
./configure --no-regex --no-pcre2 --fuzz=$LIB_FUZZING_ENGINE | ||
make fuzz -j$(nproc) | ||
|
||
mkdir -p build/fuzz_basic_seed | ||
mkdir -p build/fuzz_http_controller_seed | ||
mkdir -p build/fuzz_http_h1p_seed | ||
mkdir -p build/fuzz_http_h1p_peer_seed | ||
mkdir -p build/fuzz_json_seed | ||
|
||
echo "" | ||
echo "Run: ./build/\${fuzzer} build/\${fuzzer}_seed src/fuzz/\${fuzzer}_seed_corpus" | ||
echo "" |
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,29 @@ | ||
#!/bin/bash -eu | ||
|
||
# Build unit | ||
./configure --no-regex --no-pcre2 --fuzz="$LIB_FUZZING_ENGINE" | ||
make fuzz -j"$(nproc)" | ||
|
||
# Copy all fuzzers. | ||
cp build/fuzz_* $OUT/ | ||
|
||
# cd into fuzzing dir | ||
pushd fuzzing/ | ||
cp fuzz_http.dict $OUT/fuzz_http_controller.dict | ||
cp fuzz_http.dict $OUT/fuzz_http_h1p.dict | ||
cp fuzz_http.dict $OUT/fuzz_http_h1p_peer.dict | ||
|
||
# Create temporary directories. | ||
cp -r fuzz_http_seed_corpus/ fuzz_http_controller_seed_corpus/ | ||
cp -r fuzz_http_seed_corpus/ fuzz_http_h1p_seed_corpus/ | ||
cp -r fuzz_http_seed_corpus/ fuzz_http_h1p_peer_seed_corpus/ | ||
|
||
zip -r $OUT/fuzz_basic_seed_corpus.zip fuzz_basic_seed_corpus/ | ||
zip -r $OUT/fuzz_http_controller_seed_corpus.zip fuzz_http_controller_seed_corpus/ | ||
zip -r $OUT/fuzz_http_h1p_seed_corpus.zip fuzz_http_h1p_seed_corpus/ | ||
zip -r $OUT/fuzz_http_h1p_peer_seed_corpus.zip fuzz_http_h1p_peer_seed_corpus/ | ||
zip -r $OUT/fuzz_json_seed_corpus.zip fuzz_json_seed_corpus/ | ||
|
||
# Delete temporary directories. | ||
rm -r fuzz_http_controller_seed_corpus/ fuzz_http_h1p_seed_corpus/ fuzz_http_h1p_peer_seed_corpus/ | ||
popd |