tree: 8651f314e930b4338ebad187392275ef9e92d341 [path history] [tgz]
  1. static_seed/
  2. .gitignore
  3. api.c
  4. fuzz.c
  5. fuzz.h
  6. genSeed.c
  7. html.c
  8. html.dict
  9. html.options
  10. Makefile.am
  11. oss-fuzz-build.sh
  12. README.md
  13. regexp.c
  14. regexp.dict
  15. regexp.options
  16. schema.c
  17. schema.dict
  18. schema.options
  19. testFuzzer.c
  20. uri.c
  21. uri.options
  22. valid.c
  23. valid.options
  24. xinclude.c
  25. xinclude.options
  26. xml.c
  27. xml.dict
  28. xml.options
  29. xpath.c
  30. xpath.dict
  31. xpath.options
fuzz/README.md

libFuzzer instructions for libxml2

Set compiler and options. Make sure to enable at least basic optimizations to avoid excessive stack usage. Also enable some debug output to get meaningful stack traces.

export CC=clang
export CFLAGS=" \
    -O1 -gline-tables-only \
    -fsanitize=fuzzer-no-link,address,undefined \
    -fno-sanitize-recover=all \
    -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION"

Other options that can improve stack traces:

-fno-omit-frame-pointer
-fno-inline
-fno-optimize-sibling-calls (disables tail call optimization)

Build libxml2 with instrumentation:

./configure --without-python
make

Run fuzzers:

make -C fuzz fuzz-xml

The environment variable XML_FUZZ_OPTIONS can be used to pass additional flags to the fuzzer.

Malloc failure injection

Most fuzzers inject malloc failures to cover code paths handling these errors. This can lead to surprises when debugging crashes. You can set the macro XML_FUZZ_MALLOC_ABORT in fuzz/fuzz.c to make the fuzz target abort at the malloc invocation which would fail. This tells you if and where a malloc failure was injected.

Some fuzzers also test whether malloc failures are reported. To debug failures which aren‘t reported, it’s helpful to enable XML_FUZZ_MALLOC_ABORT to see which allocation failed. Debugging failures which are erroneously reported can be harder. If the report goes through xmlRaiseMemoryError, you can abort() there to get a stack trace.