Debian Codegraph @

c/tests/fuzz/README.md

raw
1 # Fuzz testing for qpid-proton-c
2
3 ## Dockerfile
4
5 Easiest way to build and run the fuzzing is using attached Dockerfile. Run the following command from the top directory of the project
6
7 docker build -f proton-c/src/tests/fuzz/Dockerfile -t qpid-proton-fuzz .
8
9 Then run the built image and execute a fuzzer to check that all works
10
11 docker run --cap-add SYS_PTRACE -it qpid-proton-fuzz
12 ./fuzz-url /src/proton-c/src/tests/fuzz/fuzz-url/crash /src/proton-c/src/tests/fuzz/fuzz-url/corpus
13
14 You can bind a local directory to the container with the `-v local:remote` option. The `--rm` option is also useful. See https://docs.docker.com/engine/reference/run/.
15
16 The docker image is based on `ossfuzz/basebuilder`, which is Ubuntu 16.04 Xenial with clang 5.0 and libc++.
17
18 ## Building
19
20 There are two cmake options to control compilation of fuzzers
21
22 * `FUZZ_TEST` (default: `OFF`) adds fuzzers to the build and to regression tests
23 * `FUZZING_ENGINE` (default: `OFF`) links fuzzers with `libFuzzingEngine` when `ON`
24
25 When `FUZZING_ENGINE` is `OFF`, fuzzers are linked with a simple driver suitable only for regression testing.
26
27 ### with a simple driver
28
29 There are no special prerequisites and no extra configuration is necessary.
30
31 ### with libFuzzer
32
33 1. Download and compile libFuzzer. Use http://llvm.org/docs/LibFuzzer.html for detailed instructions.
34 2. Rename/link `libFuzzer.a` (from previous step) to `libFuzzingEngine.a`
35 3. Build qpid-proton with the following configuration
36 * set `CC` and `CXX` variables to the same compiler you used to build libFuzzer (some recent clang)
37 * set `CFLAGS` and `CXXFLAGS` with the coverage and sanitizer(s) you want to use, see libFuzzer documentation for details
38 * set `LDFLAGS` to add the directory with `libFuzzingEngine.a` to your link path if necessary
39 * set `FUZZ_TEST=ON` and `FUZZING_ENGINE=ON`
40
41 For example:
42
43 FLAGS="-fsanitize-coverage=trace-pc-guard -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls"
44
45 CC=~/third_party/llvm-build/Release+Asserts/bin/clang \
46 CXX=~/third_party/llvm-build/Release+Asserts/bin/clang++ \
47 CFLAGS="$FLAGS" \
48 CXXFLAGS="$FLAGS" \
49 LDFLAGS="-L/path/to/libFuzzingEngine/directory" \
50 cmake .. -DCMAKE_BUILD_TYPE=Debug -DFUZZ_TEST=ON -DFUZZING_ENGINE=ON
51
52 ## Running
53
54 Execute one of the `fuzz-*` binaries.
55
56 ### With simple driver
57
58 When given file paths as command line arguments, it will run the fuzzed function with each of the inputs in turn once and then exit.
59
60 ### WIth libFuzzer
61
62 When given a folder as first argument, it will load corpus from the folder and also store newly discovered inputs (that extend code coverage) there. See http://llvm.org/docs/LibFuzzer.html for details.
63
64 # Justifications
65
66 The reason for renaming the fuzzing library to `libFuzzingEngine` is to be compatible with https://github.com/google/oss-fuzz.
67
68 In fuzzing data directories, corpus and crashes are two different subdirectories, because fuzzers can perform corpus minimization. Crashes should not be subjected to corpus minimization, so they need to be kept separately.