• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2
3# OSS-Fuzz integration, see
4# https://github.com/google/oss-fuzz/tree/master/projects/libxml2
5
6# Add extra UBSan checks
7if [ "$SANITIZER" = undefined ]; then
8    extra_checks="integer,float-divide-by-zero"
9    extra_cflags="-fsanitize=$extra_checks -fno-sanitize-recover=$extra_checks"
10    export CFLAGS="$CFLAGS $extra_cflags"
11    export CXXFLAGS="$CXXFLAGS $extra_cflags"
12fi
13
14# Don't enable zlib and liblzma with MSan
15if [ "$SANITIZER" = memory ]; then
16    CONFIG=''
17else
18    CONFIG='--with-zlib --with-lzma'
19fi
20
21# Workaround for a LeakSanitizer crashes,
22# see https://github.com/google/oss-fuzz/issues/11798.
23if [ "$ARCHITECTURE" = "aarch64" ]; then
24    export ASAN_OPTIONS=detect_leaks=0
25fi
26
27export V=1
28
29./autogen.sh \
30    --disable-shared \
31    --without-debug \
32    --without-http \
33    --without-python \
34    $CONFIG
35make -j$(nproc)
36
37cd fuzz
38make clean-corpus
39make fuzz.o
40
41for fuzzer in \
42    api html lint reader regexp schema uri valid xinclude xml xpath
43do
44    OBJS="$fuzzer.o"
45    if [ "$fuzzer" = lint ]; then
46        OBJS="$OBJS ../xmllint.o ../shell.o"
47    fi
48    make $OBJS
49    # Link with $CXX
50    $CXX $CXXFLAGS \
51        $OBJS fuzz.o \
52        -o $OUT/$fuzzer \
53        $LIB_FUZZING_ENGINE \
54        ../.libs/libxml2.a -Wl,-Bstatic -lz -llzma -Wl,-Bdynamic
55
56    if [ $fuzzer != api ]; then
57        [ -e seed/$fuzzer ] || make seed/$fuzzer.stamp
58        zip -j $OUT/${fuzzer}_seed_corpus.zip seed/$fuzzer/*
59    fi
60done
61
62cp *.dict *.options $OUT/
63