export CC="/opt/homebrew/Cellar/llvm/18.1.8/bin/clang" export CXX="/opt/homebrew/Cellar/llvm/18.1.8/bin/clang++"
RelWithDebInfo
:export CFLAGS="-fsanitize=address,fuzzer-no-link -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION" export CXXFLAGS="-fsanitize=address,fuzzer-no-link -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION" export LDFLAGS="-fsanitize=address,fuzzer-no-link" mkdir buildfuzz cd buildfuzz cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -G Ninja .. ninja
${CC} -W -Wall -Og -fsanitize=address,fuzzer -I../include -I../src/lib -I. -o ares-test-fuzz ../test/ares-test-fuzz.c -L./lib -Wl,-rpath ./lib -lcares ${CC} -W -Wall -Og -fsanitize=address,fuzzer -I../include -I../src/lib -I. -o ares-test-fuzz-name ../test/ares-test-fuzz-name.c -L./lib -Wl,-rpath ./lib -lcares
-jobs=XX
for parallelism. See https://llvm.org/docs/LibFuzzer.htmlmkdir corpus cp ../test/fuzzinput/* corpus ./ares-test-fuzz -max_len=65535 corpus
or
mkdir corpus cp ../test/fuzznames/* corpus ./ares-test-fuzz-name -max_len=1024 corpus
To fuzz using AFL, follow the AFL quick start guide:
Download and build AFL.
Configure the c-ares library and test tool to use AFL's compiler wrappers:
% export CC=$AFLDIR/afl-gcc % ./configure --disable-shared && make % cd test && ./configure && make aresfuzz aresfuzzname
Run the AFL fuzzer against the starting corpus:
% mkdir fuzzoutput % $AFLDIR/afl-fuzz -i fuzzinput -o fuzzoutput -- ./aresfuzz # OR % $AFLDIR/afl-fuzz -i fuzznames -o fuzzoutput -- ./aresfuzzname
If a recent version of Clang is available, AFL can use its built-in compiler instrumentation; this configuration also allows the use of a (much) faster persistent mode, where multiple fuzz inputs are run for each process invocation.
Download and build a recent AFL, and run make
in the llvm_mode
subdirectory to ensure that afl-clang-fast
gets built.
Configure the c-ares library and test tool to use AFL's clang wrappers that use compiler instrumentation:
% export CC=$AFLDIR/afl-clang-fast % ./configure --disable-shared && make % cd test && ./configure && make aresfuzz
Run the AFL fuzzer (in persistent mode) against the starting corpus:
% mkdir fuzzoutput % $AFLDIR/afl-fuzz -i fuzzinput -o fuzzoutput -- ./aresfuzz