]> git.proxmox.com Git - ceph.git/blame - ceph/src/fmt/test/fuzzing/README.md
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / fmt / test / fuzzing / README.md
CommitLineData
f67539c2
TL
1# FMT Fuzzer
2
3Fuzzing has revealed [several bugs](https://github.com/fmtlib/fmt/issues?&q=is%3Aissue+fuzz)
4in fmt. It is a part of the continous fuzzing at
5[oss-fuzz](https://github.com/google/oss-fuzz).
6
7The source code is modified to make the fuzzing possible without locking up on
8resource exhaustion:
9```cpp
10#ifdef FMT_FUZZ
11if(spec.precision>100000) {
12 throw std::runtime_error("fuzz mode - avoiding large precision");
13}
14#endif
15```
16This macro `FMT_FUZZ` is enabled on OSS-Fuzz builds and makes fuzzing
17practically possible. It is used in fmt code to prevent resource exhaustion in
18fuzzing mode.
19The macro `FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION` is the
20defacto standard for making fuzzing practically possible to disable certain
21fuzzing-unfriendly features (for example, randomness), see [the libFuzzer
22documentation](https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode).
23
24## Running the fuzzers locally
25
26There is a [helper script](build.sh) to build the fuzzers, which has only been
27tested on Debian and Ubuntu linux so far. There should be no problems fuzzing on
28Windows (using clang>=8) or on Mac, but the script will probably not work out of
29the box.
30
31Something along
32```sh
33mkdir build
34cd build
35export CXX=clang++
36export CXXFLAGS="-fsanitize=fuzzer-no-link -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION= -g"
37cmake .. -DFMT_SAFE_DURATION_CAST=On -DFMT_FUZZ=On -DFMT_FUZZ_LINKMAIN=Off -DFMT_FUZZ_LDFLAGS="-fsanitize=fuzzer"
38cmake --build .
39```
40should work to build the fuzzers for all platforms which clang supports.
41
42Execute a fuzzer with for instance
43```sh
44cd build
45export UBSAN_OPTIONS=halt_on_error=1
46mkdir out_chrono
47bin/fuzzer_chrono_duration out_chrono
48```