1#!/bin/bash -eu 2# Copyright 2019 Google Inc. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16################################################################################ 17 18# build oniguruma and link statically 19pushd oniguruma 20autoreconf -vfi 21./configure 22make -j$(nproc) 23popd 24export ONIG_CFLAGS="-I$PWD/oniguruma/src" 25export ONIG_LIBS="-L$PWD/oniguruma/src/.libs -l:libonig.a" 26 27# PHP's zend_function union is incompatible with the object-size sanitizer 28export CFLAGS="$CFLAGS -fno-sanitize=object-size" 29export CXXFLAGS="$CXXFLAGS -fno-sanitize=object-size" 30 31# build project 32./buildconf 33./configure \ 34 --disable-all \ 35 --enable-option-checking=fatal \ 36 --enable-fuzzer \ 37 --enable-json \ 38 --enable-exif \ 39 --enable-mbstring \ 40 --without-pcre-jit \ 41 --disable-phpdbg \ 42 --disable-cgi \ 43 --with-pic 44make -j$(nproc) 45 46# Generate dictionary for unserialize fuzzer 47sapi/cli/php sapi/fuzzer/generate_unserialize_dict.php 48cp sapi/fuzzer/dict/unserialize $OUT/php-fuzz-unserialize.dict 49 50# Generate initial corpus for parser fuzzer 51sapi/cli/php sapi/fuzzer/generate_parser_corpus.php 52cp sapi/fuzzer/dict/parser $OUT/php-fuzz-parser.dict 53 54cp sapi/fuzzer/json.dict $OUT/php-fuzz-json.dict 55 56FUZZERS="php-fuzz-json php-fuzz-exif php-fuzz-mbstring php-fuzz-unserialize php-fuzz-parser" 57for fuzzerName in $FUZZERS; do 58 cp sapi/fuzzer/$fuzzerName $OUT/ 59done 60# copy corpora from source 61for fuzzerName in `ls sapi/fuzzer/corpus`; do 62 zip -j $OUT/php-fuzz-${fuzzerName}_seed_corpus.zip sapi/fuzzer/corpus/${fuzzerName}/* 63done 64 65