mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-07 08:31:16 +00:00
9d97201ede
see https://github.com/google/oss-fuzz/pull/2381 the history of the fuzz branch is long and messy and is difficult to rebase on top of the current master. Squashed commit of the following: commit b9d6db50010e185d0af2590a35472e9334102248 Author: Paul Dreik <github@pauldreik.se> Date: Sat Jun 29 21:50:34 2019 +0200 update exception with a more accurate description commit f3fbaf60cc80c7f57fa95962dc0069b10c3d3e61 Author: Paul Dreik <github@pauldreik.se> Date: Sat Jun 29 21:34:55 2019 +0200 fix missing flags in reproduce build commit 40a17bec7a1ad724203577842a254ca9c42da388 Author: Paul Dreik <github@pauldreik.se> Date: Sat Jun 29 21:22:48 2019 +0200 move check for large precision values closer to where needed commit ef6e23e1f52d639c5aec1a1e713157cec380a8c3 Author: Paul Dreik <github@pauldreik.se> Date: Fri Jun 28 20:55:34 2019 +0200 simplify the fuzzer build script commit eadee6e0557be6df695e80f0f2717046a29846e0 Author: Paul Dreik <github@pauldreik.se> Date: Fri Jun 28 20:47:54 2019 +0200 minimize source code pollution commit 1ece6416438f199c164ee9aa89f42ad1f21a4985 Merge: f404079b |
||
---|---|---|
.. | ||
.gitignore | ||
build.sh | ||
chrono_duration.cpp | ||
CMakeLists.txt | ||
fuzzer_common.h | ||
main.cpp | ||
named_arg.cpp | ||
one_arg.cpp | ||
README.md | ||
sprintf.cpp | ||
two_args.cpp |
FMT Fuzzer
Fuzzing has revealed several bugs in fmt. It is a part of the continous fuzzing at oss-fuzz
The source code is modified to make the fuzzing possible without locking up on resource exhaustion:
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
if(spec.precision>100000) {
throw std::runtime_error("fuzz mode - avoiding large precision");
}
#endif
This macro is the defacto standard for making fuzzing practically possible, see the libFuzzer documentation.
Running the fuzzers locally
There is a helper script to build the fuzzers, which has only been tested on Debian and Ubuntu linux so far. There should be no problems fuzzing on Windows (using clang>=8) or on Mac, but the script will probably not work out of the box.
Something along
mkdir build
cd build
export CXX=clang++
export CXXFLAGS="-fsanitize=fuzzer-no-link -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION= -g"
cmake .. -DFMT_SAFE_DURATION_CAST=On -DFMT_FUZZ=On -DFMT_FUZZ_LINKMAIN=Off -DFMT_FUZZ_LDFLAGS="-fsanitize=fuzzer"
cmake --build .
should work to build the fuzzers for all platforms which clang supports.
Execute a fuzzer with for instance
cd build
export UBSAN_OPTIONS=halt_on_error=1
mkdir out_chrono
bin/fuzzer_chrono_duration out_chrono