2020-01-08 16:02:45 +00:00
|
|
|
#!/bin/bash -u
|
|
|
|
# Copyright 2020 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.
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
# Wrapper around bad_build_check that moves the /out directory to /tmp/not-out.
|
|
|
|
# This is useful when bad_build_check isn't called from test_all which does the
|
|
|
|
# same thing.
|
|
|
|
|
|
|
|
function main {
|
|
|
|
# Move the directory the fuzzer is located in to somewhere that doesn't exist
|
|
|
|
# on the builder to make it more likely that hardcoding /out fails here (since
|
|
|
|
# it will fail on ClusterFuzz).
|
|
|
|
local fuzzer=$1
|
|
|
|
fuzzer=$(realpath $fuzzer)
|
|
|
|
local initial_fuzzer_dir=$(dirname $fuzzer)
|
|
|
|
|
|
|
|
local tmp_fuzzer_dir=/tmp/not-out
|
|
|
|
rm -rf $tmp_fuzzer_dir
|
|
|
|
mkdir $tmp_fuzzer_dir
|
|
|
|
# Move the contents of $initial_fuzzer_dir rather than the directory itself in
|
|
|
|
# case it is a mount.
|
|
|
|
mv $initial_fuzzer_dir/* $tmp_fuzzer_dir
|
|
|
|
fuzzer="$tmp_fuzzer_dir/$(basename $fuzzer)"
|
|
|
|
|
2020-01-08 16:03:29 +00:00
|
|
|
# Change OUT to the temporary fuzzer dir.
|
|
|
|
local initial_out=$OUT
|
|
|
|
export OUT=$tmp_fuzzer_dir
|
|
|
|
|
2020-01-08 16:02:45 +00:00
|
|
|
bad_build_check $fuzzer
|
|
|
|
returncode=$?
|
|
|
|
|
2020-01-08 16:03:29 +00:00
|
|
|
# Restore OUT and $initial_fuzzer_dir
|
|
|
|
export OUT=$initial_out
|
2020-01-08 16:02:45 +00:00
|
|
|
mv $tmp_fuzzer_dir/* $initial_fuzzer_dir
|
2020-01-08 16:03:29 +00:00
|
|
|
|
|
|
|
return $returncode
|
2020-01-08 16:02:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# -ne 1 ]; then
|
|
|
|
echo "Usage: $0 <fuzz_target_binary>"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
main $1
|
2020-01-08 16:03:29 +00:00
|
|
|
exit $?
|