2017-01-05 21:27:53 +00:00
|
|
|
#!/bin/bash -eu
|
|
|
|
# Copyright 2016 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.
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
|
2022-01-20 17:17:07 +00:00
|
|
|
# Temporarily disable randomization and enforce a safe and sane setup
|
|
|
|
export AFL_SKIP_OSSFUZZ=1
|
|
|
|
export AFL_LLVM_INSTRUMENT=CLASSIC
|
|
|
|
|
2022-01-18 19:54:28 +00:00
|
|
|
# In emergencies where afl++'s own compiler fails set this to "1":
|
|
|
|
export AFL_LLVM_MODE_WORKAROUND=0
|
|
|
|
|
2021-11-30 13:13:58 +00:00
|
|
|
# AFL++ setup
|
|
|
|
echo "Copying precompiled AFL++"
|
2021-03-04 14:19:53 +00:00
|
|
|
|
2021-11-30 13:13:58 +00:00
|
|
|
# Copy AFL++ tools necessary for fuzzing.
|
2021-01-25 17:14:11 +00:00
|
|
|
pushd $SRC/aflplusplus > /dev/null
|
2018-04-30 20:17:13 +00:00
|
|
|
|
2021-02-18 20:55:07 +00:00
|
|
|
cp -f libAFLDriver.a $LIB_FUZZING_ENGINE
|
2018-04-30 20:17:13 +00:00
|
|
|
|
2021-01-25 17:14:11 +00:00
|
|
|
# Some important projects include libraries, copy those even when they don't
|
|
|
|
# start with "afl-". Use "sort -u" to avoid a warning about duplicates.
|
2021-02-02 00:20:18 +00:00
|
|
|
ls afl-* *.txt *.a *.o *.so | sort -u | xargs cp -t $OUT
|
|
|
|
export CC="$SRC/aflplusplus/afl-clang-fast"
|
|
|
|
export CXX="$SRC/aflplusplus/afl-clang-fast++"
|
|
|
|
|
2021-11-30 13:13:58 +00:00
|
|
|
# Set sane AFL++ environment defaults:
|
2021-02-06 22:58:58 +00:00
|
|
|
# Be quiet, otherwise this can break some builds.
|
|
|
|
export AFL_QUIET=1
|
|
|
|
# No leak errors during builds.
|
2021-03-04 14:19:53 +00:00
|
|
|
export ASAN_OPTIONS="detect_leaks=0:symbolize=0:detect_odr_violation=0:abort_on_error=1"
|
2022-01-18 19:54:28 +00:00
|
|
|
# Do not abort on any problems (because this is during build where it is ok)
|
|
|
|
export AFL_IGNORE_PROBLEMS=1
|
2021-11-30 13:13:58 +00:00
|
|
|
# No complain on unknown AFL environment variables
|
|
|
|
export AFL_IGNORE_UNKNOWN_ENVS=1
|
2021-02-18 20:55:07 +00:00
|
|
|
|
2021-11-30 13:13:58 +00:00
|
|
|
# To analyze build failures and set specific AFL++ settings, set
|
|
|
|
# `export AFL_SKIP_OSSFUZZ=1`
|
|
|
|
# The 'env|grep' setup ensures we do not trigger the linter.
|
|
|
|
env | egrep -q '^AFL_SKIP_OSSFUZZ=' || {
|
|
|
|
|
|
|
|
# The variables need to be set to "1" here - or before running this script.
|
|
|
|
# AFL++ configuration options.
|
|
|
|
export AFL_ENABLE_DICTIONARY=0
|
|
|
|
export AFL_ENABLE_CMPLOG=1
|
|
|
|
export AFL_LAF_CHANCE=5
|
|
|
|
|
|
|
|
#
|
|
|
|
# AFL++ compile option roulette. It is OK if they all happen together.
|
|
|
|
#
|
|
|
|
|
|
|
|
# 20% chance for CTX-2 coverage instrumentation (Caller conTeXt sensitive
|
|
|
|
# edge coverage).
|
|
|
|
test $(($RANDOM % 100)) -lt 20 && {
|
|
|
|
export AFL_LLVM_INSTRUMENT=CLASSIC,CTX-2
|
|
|
|
export AFL_ENABLE_CMPLOG=0
|
|
|
|
# we increase the chance for LAF because we do not do CMPLOG with CTX
|
2022-01-11 13:08:49 +00:00
|
|
|
export AFL_LAF_CHANCE=20
|
2021-11-30 13:13:58 +00:00
|
|
|
}
|
2021-02-18 20:55:07 +00:00
|
|
|
|
2021-11-30 13:13:58 +00:00
|
|
|
# 40% chance to create a dictionary.
|
|
|
|
test $(($RANDOM % 100)) -lt 40 && {
|
|
|
|
export AFL_ENABLE_DICTIONARY=1
|
|
|
|
}
|
2021-04-02 14:02:26 +00:00
|
|
|
|
2021-11-30 13:13:58 +00:00
|
|
|
# 60% chance to perform CMPLOG/REDQUEEN.
|
|
|
|
rm -f "$OUT/afl_cmplog.txt"
|
|
|
|
test "$AFL_ENABLE_CMPLOG" = "1" -a $(($RANDOM % 100)) -lt 60 && {
|
|
|
|
export AFL_LLVM_CMPLOG=1
|
|
|
|
touch "$OUT/afl_cmplog.txt"
|
|
|
|
}
|
2021-05-24 20:43:34 +00:00
|
|
|
|
2021-11-30 13:13:58 +00:00
|
|
|
# chance to perform COMPCOV/LAF_INTEL - if CMPLOG is not enabled.
|
|
|
|
test $(($RANDOM % 100)) -lt $AFL_LAF_CHANCE -a "$AFL_ENABLE_CMPLOG" = "0" && {
|
|
|
|
export AFL_LLVM_LAF_ALL=1
|
|
|
|
}
|
2021-02-18 20:55:07 +00:00
|
|
|
|
2021-11-30 13:13:58 +00:00
|
|
|
#
|
|
|
|
# End of AFL++ compile option roulette
|
|
|
|
#
|
|
|
|
|
|
|
|
# Create a dictionary if one is wanted.
|
|
|
|
test "$AFL_ENABLE_DICTIONARY" = "1" && {
|
|
|
|
export AFL_LLVM_DICT2FILE="$OUT/afl++.dict"
|
|
|
|
}
|
2021-02-18 20:55:07 +00:00
|
|
|
|
2021-03-04 14:19:53 +00:00
|
|
|
}
|
2021-03-04 03:10:35 +00:00
|
|
|
|
2021-02-18 20:55:07 +00:00
|
|
|
# In case afl-clang-fast ever breaks, this is a workaround:
|
|
|
|
test "$AFL_LLVM_MODE_WORKAROUND" = "1" && {
|
|
|
|
export CC=clang
|
|
|
|
export CXX=clang++
|
|
|
|
WORKAROUND_FLAGS=-fsanitize-coverage=trace-pc-guard
|
|
|
|
# We can still do CMPLOG light:
|
|
|
|
test -e "$OUT/afl_cmplog.txt" && {
|
|
|
|
WORKAROUND_FLAGS="$WORKAROUND_FLAGS",trace-cmp
|
|
|
|
}
|
|
|
|
export CFLAGS="$CFLAGS $WORKAROUND_FLAGS"
|
|
|
|
export CXXFLAGS="$CXXFLAGS $WORKAROUND_FLAGS"
|
2021-03-04 14:19:53 +00:00
|
|
|
unset AFL_LLVM_LAF_ALL
|
|
|
|
unset AFL_LLVM_DICT2FILE
|
|
|
|
unset AFL_ENABLE_DICTIONARY
|
2021-02-18 20:55:07 +00:00
|
|
|
# We need to create a new fuzzer lib however.
|
|
|
|
ar ru libAFLDrivernew.a afl-compiler-rt.o utils/aflpp_driver/aflpp_driver.o
|
|
|
|
cp -f libAFLDrivernew.a $LIB_FUZZING_ENGINE
|
|
|
|
}
|
|
|
|
|
2021-11-30 13:13:58 +00:00
|
|
|
# Provide a way to document the AFL++ options used in this build:
|
2021-03-04 14:19:53 +00:00
|
|
|
echo
|
2021-11-30 13:13:58 +00:00
|
|
|
echo AFL++ target compilation setup:
|
|
|
|
env | egrep '^AFL_' | tee "$OUT/afl_options.txt"
|
2021-03-04 14:19:53 +00:00
|
|
|
echo
|
2021-02-18 20:55:07 +00:00
|
|
|
|
|
|
|
popd > /dev/null
|
2021-02-06 22:58:58 +00:00
|
|
|
|
2017-01-05 21:27:53 +00:00
|
|
|
echo " done."
|