Debian Codegraph @

fuzz/README.md

raw
1 libFuzzer instructions for libxml2
2 ==================================
3
4 Set compiler and options. Make sure to enable at least basic optimizations
5 to avoid excessive stack usage. Also enable some debug output to get
6 meaningful stack traces.
7
8 export CC=clang
9 export CFLAGS=" \
10 -O1 -gline-tables-only \
11 -fsanitize=fuzzer-no-link,address,undefined \
12 -fno-sanitize-recover=all \
13 -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION"
14
15 Since llvm-symbolizer can use libxml2 itself, you may need the following
16 wrapper to make sure that it doesn't use the instrumented version of
17 libxml2:
18
19 export ASAN_SYMBOLIZER_PATH="$(pwd)/.gitlab-ci/llvm-symbolizer"
20
21 Other options that can improve stack traces:
22
23 -fno-omit-frame-pointer
24 -fno-inline
25 -fno-optimize-sibling-calls (disables tail call optimization)
26
27 Build libxml2 with instrumentation:
28
29 ./configure --without-python
30 make
31
32 Run fuzzers:
33
34 make -C fuzz fuzz-xml
35
36 The environment variable XML_FUZZ_OPTIONS can be used to pass additional
37 flags to the fuzzer.
38
39 Malloc failure injection
40 ------------------------
41
42 Most fuzzers inject malloc failures to cover code paths handling these
43 errors. This can lead to surprises when debugging crashes. You can set
44 the macro XML_FUZZ_MALLOC_ABORT in fuzz/fuzz.c to make the fuzz target
45 abort at the malloc invocation which would fail. This tells you if
46 and where a malloc failure was injected.
47
48 Some fuzzers also test whether malloc failures are reported. To debug
49 failures which aren't reported, it's helpful to enable
50 XML_FUZZ_MALLOC_ABORT to see which allocation failed. Debugging
51 failures which are erroneously reported can be harder. If the report
52 goes through xmlRaiseMemoryError, you can abort() there to get a
53 stack trace.
54
55 Bugs related to handling of malloc failures are not considered
56 security-critical by the libxml2 maintainers. Nevertheless, we'd like
57 to see such issues reported.