diff --git a/fuzzing/engines/BUILD b/fuzzing/engines/BUILD index ab38bc44..9d368d5e 100644 --- a/fuzzing/engines/BUILD +++ b/fuzzing/engines/BUILD @@ -23,6 +23,9 @@ cc_fuzzing_engine( name = "libfuzzer", display_name = "libFuzzer", launcher = "libfuzzer_launcher.sh", + launcher_data = { + "//fuzzing/tools:realpath": "REALPATH_PATH", + }, library = ":libfuzzer_stub", visibility = ["//visibility:public"], ) @@ -46,6 +49,7 @@ cc_fuzzing_engine( launcher = "honggfuzz_launcher.sh", launcher_data = { "@honggfuzz//:honggfuzz": "HONGGFUZZ_PATH", + "//fuzzing/tools:realpath": "REALPATH_PATH", }, library = "@honggfuzz//:honggfuzz_engine", visibility = ["//visibility:public"], @@ -58,6 +62,9 @@ cc_fuzzing_engine( name = "replay", display_name = "Replay", launcher = "replay_launcher.sh", + launcher_data = { + "//fuzzing/tools:realpath": "REALPATH_PATH", + }, library = "//fuzzing/replay:replay_main", visibility = ["//visibility:public"], ) @@ -69,6 +76,9 @@ java_fuzzing_engine( name = "jazzer", display_name = "Jazzer", launcher = "jazzer_launcher.sh", + launcher_data = { + "//fuzzing/tools:realpath": "REALPATH_PATH", + }, library = "@jazzer//agent:jazzer_api_compile_only", visibility = ["//visibility:public"], ) diff --git a/fuzzing/engines/honggfuzz_launcher.sh b/fuzzing/engines/honggfuzz_launcher.sh index 9c0bf621..25faf062 100755 --- a/fuzzing/engines/honggfuzz_launcher.sh +++ b/fuzzing/engines/honggfuzz_launcher.sh @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -command_line="$(python3 -c 'import os, sys; print(os.path.realpath(sys.argv[1]))' ${HONGGFUZZ_PATH})" +command_line="$("${REALPATH_PATH}" ${HONGGFUZZ_PATH})" command_line+=("--workspace=${FUZZER_OUTPUT_ROOT}") if [[ -n "${FUZZER_SEED_CORPUS_DIR}" ]]; then diff --git a/fuzzing/engines/jazzer_launcher.sh b/fuzzing/engines/jazzer_launcher.sh index c1601e54..81821f3f 100755 --- a/fuzzing/engines/jazzer_launcher.sh +++ b/fuzzing/engines/jazzer_launcher.sh @@ -16,7 +16,7 @@ # engine. The launch configuration is supplied by the launcher script through # environment variables. -command_line=("$(python3 -c 'import os, sys; print(os.path.realpath(sys.argv[1]))' ${FUZZER_BINARY})") +command_line=("$("${REALPATH_PATH}" ${FUZZER_BINARY})") # libFuzzer flags (compatible with Jazzer). diff --git a/fuzzing/engines/libfuzzer_launcher.sh b/fuzzing/engines/libfuzzer_launcher.sh index 6346db8a..7a59e049 100755 --- a/fuzzing/engines/libfuzzer_launcher.sh +++ b/fuzzing/engines/libfuzzer_launcher.sh @@ -16,7 +16,7 @@ # libFuzzer engine. The launch configuration is supplied by the launcher # script through environment variables. -command_line=("$(python3 -c 'import os, sys; print(os.path.realpath(sys.argv[1]))' ${FUZZER_BINARY})") +command_line=("$("${REALPATH_PATH}" ${FUZZER_BINARY})") # libFuzzer flags. diff --git a/fuzzing/engines/replay_launcher.sh b/fuzzing/engines/replay_launcher.sh index 4ebf2936..570b42ba 100755 --- a/fuzzing/engines/replay_launcher.sh +++ b/fuzzing/engines/replay_launcher.sh @@ -16,7 +16,7 @@ if (( ! FUZZER_IS_REGRESSION )); then echo "NOTE: Non-regression mode is not supported by the replay engine." fi -command_line=("$(python3 -c 'import os, sys; print(os.path.realpath(sys.argv[1]))' ${FUZZER_BINARY})") +command_line=("$("${REALPATH_PATH}" ${FUZZER_BINARY})") if [[ -n "${FUZZER_SEED_CORPUS_DIR}" ]]; then command_line+=("${FUZZER_SEED_CORPUS_DIR}") fi diff --git a/fuzzing/private/engine.bzl b/fuzzing/private/engine.bzl index 9d8656d1..39bab2c5 100644 --- a/fuzzing/private/engine.bzl +++ b/fuzzing/private/engine.bzl @@ -37,9 +37,12 @@ def _make_fuzzing_engine_info(ctx): if data_env_var: if data_env_var in env_vars: fail("Multiple data dependencies map to variable '%s'." % data_env_var) - if len(data_files) != 1: - fail("Data dependency for variable '%s' doesn't map to exactly one file." % data_env_var) - env_vars[data_env_var] = data_files[0] + if len(data_files) == 1: + env_vars[data_env_var] = data_files[0] + elif data_label.files_to_run.executable: + env_vars[data_env_var] = data_label.files_to_run.executable + else: + fail("Data dependency for variable '%s' is not a single file or executable." % data_env_var) launcher_runfiles = launcher_runfiles.merge(ctx.runfiles(files = data_files)) launcher_runfiles = launcher_runfiles.merge(data_label[DefaultInfo].default_runfiles) diff --git a/fuzzing/tools/BUILD b/fuzzing/tools/BUILD index 21691a6f..59ad6d2d 100644 --- a/fuzzing/tools/BUILD +++ b/fuzzing/tools/BUILD @@ -36,6 +36,13 @@ py_binary( deps = [requirement("absl-py")], ) +py_binary( + name = "realpath", + srcs = ["realpath.py"], + python_version = "PY3", + visibility = ["//visibility:public"], +) + py_binary( name = "validate_dict", srcs = ["validate_dict.py"], diff --git a/fuzzing/tools/realpath.py b/fuzzing/tools/realpath.py new file mode 100644 index 00000000..cfd28352 --- /dev/null +++ b/fuzzing/tools/realpath.py @@ -0,0 +1,27 @@ +# Copyright 2020 Google LLC +# +# 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 +# +# https://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. + +# Lint as: python3 +""" +Gets the realpath of a input path. + +This is a portable replacement of `readlink -f`/`realpath`. +""" + +import os, sys + +if len(sys.argv) < 2: + print("Need an argument for the input path.", file=sys.stderr) + sys.exit(1) +print(os.path.realpath(sys.argv[1]))