1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 12:25:09 +03:00
libxml2/fuzz
2024-03-16 15:20:08 +01:00
..
static_seed fuzz: Add maxAlloc item to static seed corpus 2023-03-08 14:07:15 +01:00
.gitignore fuzz: New tree API fuzzer 2024-03-15 19:54:27 +01:00
api.c fuzz: Add some comments in api.c 2024-03-15 22:07:23 +01:00
fuzz.c fuzz: New tree API fuzzer 2024-03-15 19:54:27 +01:00
fuzz.h fuzz: New tree API fuzzer 2024-03-15 19:54:27 +01:00
genSeed.c tests: Fix tests --with-valid --without-xinclude 2023-11-27 18:03:01 +01:00
html.c fuzz: New tree API fuzzer 2024-03-15 19:54:27 +01:00
html.dict Add charset names to fuzzing dictionaries 2021-02-22 13:21:38 +01:00
html.options Reduce some fuzzer timeouts 2021-03-01 20:56:40 +01:00
Makefile.am fuzz: Move fuzzer options to environment variable 2024-03-16 15:20:08 +01:00
oss-fuzz-build.sh fuzz: Add OSS-Fuzz build.sh 2024-03-15 22:07:23 +01:00
README.md fuzz: Move fuzzer options to environment variable 2024-03-16 15:20:08 +01:00
regexp.c regexp: Report malloc failures 2023-12-11 22:13:05 +01:00
regexp.dict Update fuzzing code 2020-07-31 11:55:13 +02:00
regexp.options Enforce maximum length of fuzz input 2020-12-16 16:12:07 +01:00
schema.c fuzz: Disable catalogs 2024-01-04 15:18:14 +01:00
schema.dict Fuzz target for XML Schemas 2020-06-23 16:20:27 +02:00
schema.options Enforce maximum length of fuzz input 2020-12-16 16:12:07 +01:00
testFuzzer.c fuzz: Allow to fuzz without push, reader or output modules 2023-09-21 13:05:49 +02:00
uri.c uri: Report malloc failures 2023-12-11 22:05:47 +01:00
uri.options Reduce some fuzzer timeouts 2021-03-01 20:56:40 +01:00
valid.c fuzz: Disable catalogs 2024-01-04 15:18:14 +01:00
valid.options fuzz: Add valid.options 2023-03-12 19:47:07 +01:00
xinclude.c fuzz: New tree API fuzzer 2024-03-15 19:54:27 +01:00
xinclude.options fuzz: Add separate XInclude fuzzer 2022-12-26 18:12:26 +01:00
xml.c fuzz: Reenable malloc failure check when serializing 2024-02-04 14:33:19 +01:00
xml.dict Add charset names to fuzzing dictionaries 2021-02-22 13:21:38 +01:00
xml.options Enforce maximum length of fuzz input 2020-12-16 16:12:07 +01:00
xpath.c fuzz: Add missing include 2024-01-07 15:42:46 +01:00
xpath.dict Add XPath and XPointer fuzzer 2020-08-06 14:12:32 +02:00
xpath.options Enforce maximum length of fuzz input 2020-12-16 16:12:07 +01:00

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.