2018-07-25 14:28:37 +00:00
|
|
|
#!/bin/bash -eu
|
|
|
|
# Copyright 2018 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.
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
# Case-sensitive names of internal Firefox fuzzing targets. Edit to add more.
|
|
|
|
FUZZ_TARGETS=(
|
|
|
|
SdpParser
|
|
|
|
StunParser
|
2018-08-27 13:27:12 +00:00
|
|
|
ContentParentIPC
|
2019-03-13 14:58:53 +00:00
|
|
|
# Targets which are available but disabled.
|
|
|
|
# Qcms
|
|
|
|
# ContentSecurityPolicyParser
|
2018-07-25 14:28:37 +00:00
|
|
|
)
|
|
|
|
|
2018-09-23 16:28:05 +00:00
|
|
|
# Firefox object (build) directory and configuration file.
|
|
|
|
export MOZ_OBJDIR=$WORK/obj-fuzz
|
|
|
|
export MOZCONFIG=$SRC/mozconfig.$SANITIZER
|
2018-07-25 14:28:37 +00:00
|
|
|
|
2018-08-27 13:27:12 +00:00
|
|
|
# Install dependencies. Note that bootstrap installs cargo, which must be added
|
|
|
|
# to PATH via source. In a successive run (for a different sanitizer), the
|
|
|
|
# cargo installation carries over, but bootstrap fails if cargo is not in PATH.
|
2018-07-27 15:23:43 +00:00
|
|
|
export SHELL=/bin/bash
|
2018-09-23 16:28:05 +00:00
|
|
|
[[ -f "$HOME/.cargo/env" ]] && source $HOME/.cargo/env
|
2018-07-26 17:23:07 +00:00
|
|
|
./mach bootstrap --no-interactive --application-choice browser
|
2018-07-26 19:18:30 +00:00
|
|
|
source $HOME/.cargo/env
|
2018-07-26 08:16:07 +00:00
|
|
|
|
2018-08-19 21:19:58 +00:00
|
|
|
# Update internal libFuzzer.
|
|
|
|
(cd tools/fuzzing/libfuzzer && ./clone_libfuzzer.sh HEAD)
|
2018-08-18 23:32:16 +00:00
|
|
|
|
2018-07-25 14:28:37 +00:00
|
|
|
# Build! Takes about 15 minutes on a 32 vCPU instance.
|
|
|
|
./mach build
|
|
|
|
./mach gtest buildbutdontrun
|
|
|
|
|
|
|
|
# Packages Firefox only to immediately extract the archive. Some files are
|
|
|
|
# replaced with gtest-variants, which is required by the fuzzing interface.
|
2018-10-01 13:43:21 +00:00
|
|
|
# Weighs in shy of 1GB afterwards. About double for coverage builds.
|
2018-09-24 13:15:19 +00:00
|
|
|
./mach package
|
2018-09-23 16:28:05 +00:00
|
|
|
tar -xf $MOZ_OBJDIR/dist/firefox*bz2 -C $OUT
|
|
|
|
cp -L $MOZ_OBJDIR/dist/bin/gtest/libxul.so $OUT/firefox
|
|
|
|
cp $OUT/firefox/dependentlibs.list $OUT/firefox/dependentlibs.list.gtest
|
2018-07-25 14:28:37 +00:00
|
|
|
|
2018-09-23 16:28:05 +00:00
|
|
|
# Get absolute paths of the required system libraries.
|
|
|
|
LIBRARIES=$({
|
|
|
|
xargs -I{} ldd $OUT/firefox/{} | gawk '/=> [/]/ {print $3}' | sort -u
|
|
|
|
} < $OUT/firefox/dependentlibs.list)
|
2018-07-25 14:28:37 +00:00
|
|
|
|
2018-08-27 13:27:12 +00:00
|
|
|
# Copy libraries. Less than 50MB total.
|
|
|
|
mkdir -p $OUT/lib
|
2018-09-23 16:28:05 +00:00
|
|
|
for LIBRARY in $LIBRARIES; do cp -L $LIBRARY $OUT/lib; done
|
2018-07-25 14:28:37 +00:00
|
|
|
|
|
|
|
# Build a wrapper binary for each target to set environment variables.
|
|
|
|
for FUZZ_TARGET in ${FUZZ_TARGETS[@]}
|
|
|
|
do
|
|
|
|
$CC $CFLAGS -O0 \
|
|
|
|
-DFUZZ_TARGET=$FUZZ_TARGET \
|
|
|
|
$SRC/target.c -o $OUT/$FUZZ_TARGET
|
|
|
|
done
|
2018-08-18 23:32:16 +00:00
|
|
|
|
2018-09-23 16:28:05 +00:00
|
|
|
cp $SRC/*.options $OUT
|
|
|
|
|
2018-08-18 23:32:16 +00:00
|
|
|
# SdpParser
|
2018-08-27 13:27:12 +00:00
|
|
|
find media/webrtc -iname "*.sdp" \
|
|
|
|
-type f -exec zip -qu $OUT/SdpParser_seed_corpus.zip "{}" \;
|
|
|
|
cp $SRC/fuzzdata/dicts/sdp.dict $OUT/SdpParser.dict
|
2018-08-18 23:32:16 +00:00
|
|
|
|
|
|
|
# StunParser
|
2018-08-27 13:27:12 +00:00
|
|
|
find media/webrtc -iname "*.stun" \
|
|
|
|
-type f -exec zip -qu $OUT/StunParser_seed_corpus.zip "{}" \;
|
|
|
|
cp $SRC/fuzzdata/dicts/stun.dict $OUT/StunParser.dict
|
|
|
|
|
|
|
|
# ContentParentIPC
|
|
|
|
cp $SRC/fuzzdata/settings/ipc/libfuzzer.content.blacklist.txt $OUT/firefox
|