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 make $fuzzer.o 45 # Link with $CXX 46 $CXX $CXXFLAGS \ 47 $fuzzer.o fuzz.o \ 48 -o $OUT/$fuzzer \ 49 $LIB_FUZZING_ENGINE \ 50 ../.libs/libxml2.a -Wl,-Bstatic -lz -llzma -Wl,-Bdynamic 51 52 if [ $fuzzer != api ]; then 53 [ -e seed/$fuzzer ] || make seed/$fuzzer.stamp 54 zip -j $OUT/${fuzzer}_seed_corpus.zip seed/$fuzzer/* 55 fi 56done 57 58cp *.dict *.options $OUT/ 59