2019-03-05 15:12:32 +00:00
|
|
|
#!/bin/bash -eu
|
|
|
|
# Copyright 2019 Google Inc.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
|
2019-12-14 13:46:40 +00:00
|
|
|
# PHP's zend_function union is incompatible with the object-size sanitizer
|
|
|
|
export CFLAGS="$CFLAGS -fno-sanitize=object-size"
|
|
|
|
export CXXFLAGS="$CXXFLAGS -fno-sanitize=object-size"
|
|
|
|
|
2021-09-22 12:33:06 +00:00
|
|
|
# Disable JIT profitability checks.
|
|
|
|
export CFLAGS="$CFLAGS -DPROFITABILITY_CHECKS=0"
|
|
|
|
|
2021-04-30 13:49:14 +00:00
|
|
|
# Make sure the right assembly files are picked
|
|
|
|
BUILD_FLAG=""
|
|
|
|
if [ "$ARCHITECTURE" = "i386" ]; then
|
|
|
|
BUILD_FLAG="--build=i686-pc-linux-gnu"
|
|
|
|
fi
|
|
|
|
|
2019-03-05 15:12:32 +00:00
|
|
|
# build project
|
|
|
|
./buildconf
|
2021-04-30 13:49:14 +00:00
|
|
|
./configure $BUILD_FLAG \
|
2019-09-29 13:25:34 +00:00
|
|
|
--disable-all \
|
2020-08-28 16:10:07 +00:00
|
|
|
--enable-debug-assertions \
|
2019-09-29 13:25:34 +00:00
|
|
|
--enable-option-checking=fatal \
|
|
|
|
--enable-fuzzer \
|
|
|
|
--enable-exif \
|
2021-09-22 12:33:06 +00:00
|
|
|
--enable-opcache \
|
2019-12-17 14:59:42 +00:00
|
|
|
--without-pcre-jit \
|
2019-09-29 13:25:34 +00:00
|
|
|
--disable-phpdbg \
|
|
|
|
--disable-cgi \
|
|
|
|
--with-pic
|
2019-09-20 22:06:06 +00:00
|
|
|
make -j$(nproc)
|
2019-03-13 14:31:48 +00:00
|
|
|
|
2020-06-30 16:54:25 +00:00
|
|
|
# Generate corpuses and dictionaries.
|
|
|
|
sapi/cli/php sapi/fuzzer/generate_all.php
|
2019-09-20 22:06:06 +00:00
|
|
|
|
2020-06-30 16:54:25 +00:00
|
|
|
# Copy dictionaries to expected locations.
|
|
|
|
cp sapi/fuzzer/dict/unserialize $OUT/php-fuzz-unserialize.dict
|
2019-09-24 14:08:09 +00:00
|
|
|
cp sapi/fuzzer/dict/parser $OUT/php-fuzz-parser.dict
|
2019-09-29 13:25:34 +00:00
|
|
|
cp sapi/fuzzer/json.dict $OUT/php-fuzz-json.dict
|
|
|
|
|
2020-06-30 16:54:25 +00:00
|
|
|
FUZZERS="php-fuzz-json
|
|
|
|
php-fuzz-exif
|
|
|
|
php-fuzz-unserialize
|
|
|
|
php-fuzz-unserializehash
|
2020-08-28 16:10:07 +00:00
|
|
|
php-fuzz-parser
|
|
|
|
php-fuzz-execute"
|
2019-03-13 14:31:48 +00:00
|
|
|
for fuzzerName in $FUZZERS; do
|
|
|
|
cp sapi/fuzzer/$fuzzerName $OUT/
|
|
|
|
done
|
2021-09-22 12:33:06 +00:00
|
|
|
|
|
|
|
# The JIT fuzzer is fundamentally incompatible with memory sanitizer,
|
|
|
|
# as that would require the JIT to emit msan instrumentation itself.
|
|
|
|
# In practice it is currently also incompatible with ubsan.
|
|
|
|
if [ "$SANITIZER" != "memory" ] && [ "$SANITIZER" != "undefined" ]; then
|
|
|
|
cp sapi/fuzzer/php-fuzz-function-jit $OUT/
|
2021-10-11 16:50:06 +00:00
|
|
|
cp sapi/fuzzer/php-fuzz-tracing-jit $OUT/
|
2021-09-22 12:33:06 +00:00
|
|
|
|
|
|
|
# Copy opcache.so extension, which does not support static linking.
|
|
|
|
mkdir -p $OUT/modules
|
|
|
|
cp modules/opcache.so $OUT/modules
|
|
|
|
fi
|
|
|
|
|
2019-03-13 14:31:48 +00:00
|
|
|
# copy corpora from source
|
2019-03-05 15:12:32 +00:00
|
|
|
for fuzzerName in `ls sapi/fuzzer/corpus`; do
|
|
|
|
zip -j $OUT/php-fuzz-${fuzzerName}_seed_corpus.zip sapi/fuzzer/corpus/${fuzzerName}/*
|
2019-03-09 13:35:27 +00:00
|
|
|
done
|
2019-03-13 14:31:48 +00:00
|
|
|
|