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# Case-sensitive names of internal Firefox fuzzing targets. Edit to add more. 19FUZZ_TARGETS=( 20 # WebRTC 21 SdpParser 22 StunParser 23 # IPC 24 ContentParentIPC 25 CompositorManagerParentIPC 26 ContentSecurityPolicyParser 27 FeaturePolicyParser 28 # Image 29 ImageGIF 30 ImageICO 31 ImageBMP 32 # Demuxing 33 MediaADTS 34 MediaFlac 35 MediaMP3 36 MediaOgg 37 MediaWebM 38 # MediaWAV disabled due to frequent OOMs 39) 40 41# Firefox object (build) directory and configuration file. 42export MOZ_OBJDIR=$WORK/obj-fuzz 43export MOZCONFIG=$SRC/mozconfig.$SANITIZER 44 45# Without this, a host tool used during Rust part of the build will fail 46export ASAN_OPTIONS="detect_leaks=0" 47 48# Install remaining dependencies. 49export SHELL=/bin/bash 50 51# Firefox might not be buildable on the latest Rust Nightly, so we should try 52# to use the same version that we use in our CI. 53RUST_NIGHTLY_VERSION=$(sed -n 's/^.*--channel.*\(nightly-[0-9-]*\).*$/\1/p' \ 54 $SRC/mozilla-central/taskcluster/ci/toolchain/rust.yml 55) 56 57rustup toolchain install ${RUST_NIGHTLY_VERSION} 58rustup default ${RUST_NIGHTLY_VERSION}-x86_64-unknown-linux-gnu 59 60./mach --no-interactive bootstrap --application-choice browser 61 62# Skip patches for now 63rm tools/fuzzing/libfuzzer/patches/*.patch 64touch tools/fuzzing/libfuzzer/patches/dummy.patch 65 66# Update internal libFuzzer. 67(cd tools/fuzzing/libfuzzer && ./clone_libfuzzer.sh HEAD) 68 69# Build! 70./mach build 71./mach gtest buildbutdontrun 72 73# Packages Firefox only to immediately extract the archive. Some files are 74# replaced with gtest-variants, which is required by the fuzzing interface. 75# Weighs in shy of 1GB afterwards. About double for coverage builds. 76./mach package 77tar -xf $MOZ_OBJDIR/dist/firefox*bz2 -C $OUT 78cp -L $MOZ_OBJDIR/dist/bin/gtest/libxul.so $OUT/firefox 79cp $OUT/firefox/dependentlibs.list $OUT/firefox/dependentlibs.list.gtest 80 81# Get absolute paths of the required system libraries. 82LIBRARIES=$({ 83 xargs -I{} ldd $OUT/firefox/{} | gawk '/=> [/]/ {print $3}' | sort -u 84} < $OUT/firefox/dependentlibs.list) 85 86# Copy libraries. Less than 50MB total. 87mkdir -p $OUT/lib 88for LIBRARY in $LIBRARIES; do cp -L $LIBRARY $OUT/lib; done 89 90# Build a wrapper binary for each target to set environment variables. 91for FUZZ_TARGET in ${FUZZ_TARGETS[@]} 92do 93 $CC $CFLAGS -O0 \ 94 -DFUZZ_TARGET=$FUZZ_TARGET \ 95 $SRC/target.c -o $OUT/$FUZZ_TARGET 96done 97 98cp $SRC/*.options $OUT 99 100# SdpParser 101find media/webrtc -iname "*.sdp" \ 102 -type f -exec zip -qu $OUT/SdpParser_seed_corpus.zip "{}" \; 103cp $SRC/fuzzdata/dicts/sdp.dict $OUT/SdpParser.dict 104 105# StunParser 106find media/webrtc -iname "*.stun" \ 107 -type f -exec zip -qu $OUT/StunParser_seed_corpus.zip "{}" \; 108cp $SRC/fuzzdata/dicts/stun.dict $OUT/StunParser.dict 109 110# ContentParentIPC 111cp $SRC/fuzzdata/settings/ipc/libfuzzer.content.blacklist.txt $OUT/firefox 112 113# ImageGIF 114zip -rj $OUT/ImageGIF_seed_corpus.zip $SRC/fuzzdata/samples/gif 115cp $SRC/fuzzdata/dicts/gif.dict $OUT/ImageGIF.dict 116 117# ImageICO 118zip -rj $OUT/ImageICO_seed_corpus.zip $SRC/fuzzdata/samples/ico 119 120# ImageBMP 121zip -rj $OUT/ImageBMP_seed_corpus.zip $SRC/fuzzdata/samples/bmp 122 123# MediaADTS 124zip -rj $OUT/MediaADTS_seed_corpus.zip $SRC/fuzzdata/samples/aac 125 126# MediaFlac 127zip -rj $OUT/MediaFlac_seed_corpus.zip $SRC/fuzzdata/samples/flac 128 129# MediaMP3 130zip -rj $OUT/MediaMP3_seed_corpus.zip $SRC/fuzzdata/samples/mp3 131 132# MediaOgg 133zip -rj $OUT/MediaOgg_seed_corpus.zip $SRC/fuzzdata/samples/ogg 134 135# MediaWebM 136zip -rj $OUT/MediaWebM_seed_corpus.zip $SRC/fuzzdata/samples/webm 137 138# MediaWAV 139# zip -rj $OUT/MediaWAV_seed_corpus.zip $SRC/fuzzdata/samples/wav 140