1#!/bin/bash -eu 2# 3# Copyright 2019 Google Inc. 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17################################################################################ 18 19if [ "$SANITIZER" = undefined ]; then 20 export CFLAGS="$CFLAGS -fsanitize=unsigned-integer-overflow -fno-sanitize-recover=unsigned-integer-overflow" 21 export CXXFLAGS="$CXXFLAGS -fsanitize=unsigned-integer-overflow -fno-sanitize-recover=unsigned-integer-overflow" 22fi 23 24if [ "$SANITIZER" = memory ]; then 25 # This would require an instrumented libgcrypt build. 26 CRYPTO_CONF=--without-crypto 27 CRYPTO_LIBS= 28else 29 CRYPTO_CONF=--with-crypto 30 CRYPTO_LIBS=-lgcrypt 31fi 32 33cd ../libxml2 34./autogen.sh \ 35 --disable-shared \ 36 --without-c14n \ 37 --without-legacy \ 38 --without-push \ 39 --without-python \ 40 --without-reader \ 41 --without-regexps \ 42 --without-sax1 \ 43 --without-schemas \ 44 --without-schematron \ 45 --without-valid \ 46 --without-writer \ 47 --without-zlib \ 48 --without-lzma 49make -j$(nproc) V=1 50 51cd ../libxslt 52./autogen.sh \ 53 --with-libxml-src=../libxml2 \ 54 --disable-shared \ 55 --without-python \ 56 $CRYPTO_CONF \ 57 --without-debug \ 58 --without-debugger \ 59 --without-profiler 60make -j$(nproc) V=1 61 62for file in xpath xslt fuzz; do 63 # Compile as C 64 $CC $CFLAGS \ 65 -I. -I../libxml2/include \ 66 -c tests/fuzz/$file.c \ 67 -o tests/fuzz/$file.o 68done 69 70for fuzzer in xpath xslt; do 71 # Link with $CXX 72 $CXX $CXXFLAGS \ 73 tests/fuzz/$fuzzer.o tests/fuzz/fuzz.o \ 74 -o $OUT/$fuzzer \ 75 $LIB_FUZZING_ENGINE \ 76 libexslt/.libs/libexslt.a libxslt/.libs/libxslt.a \ 77 ../libxml2/.libs/libxml2.a \ 78 $CRYPTO_LIBS 79 80 zip -j $OUT/${fuzzer}_seed_corpus.zip tests/fuzz/seed/$fuzzer/* 81done 82 83cp tests/fuzz/*.dict tests/fuzz/*.xml $OUT/ 84