diff --git a/src/cli/examples/domato.py b/src/cli/examples/domato.py index b6603b50a..7c2abc630 100755 --- a/src/cli/examples/domato.py +++ b/src/cli/examples/domato.py @@ -156,7 +156,7 @@ def main() -> None: of.tasks.create( helper.job.job_id, TaskType.generic_crash_report, - helper.target_exe_blob_name(args.target_exe, args.setup_dir), + helper.setup_relative_blob_name(args.target_exe, args.setup_dir), containers, pool_name=args.pool_name, duration=args.duration, @@ -201,7 +201,7 @@ def main() -> None: of.tasks.create( helper.job.job_id, TaskType.generic_generator, - helper.target_exe_blob_name(args.target_exe, args.setup_dir), + helper.setup_relative_blob_name(args.target_exe, args.setup_dir), containers, pool_name=args.pool_name, target_options=target_command, diff --git a/src/cli/examples/honggfuzz.py b/src/cli/examples/honggfuzz.py index 8c1b6adfe..225b7f751 100644 --- a/src/cli/examples/honggfuzz.py +++ b/src/cli/examples/honggfuzz.py @@ -101,7 +101,7 @@ def main() -> None: of.tasks.create( helper.job.job_id, TaskType.generic_crash_report, - helper.target_exe_blob_name(args.target_exe, args.setup_dir), + helper.setup_relative_blob_name(args.target_exe, args.setup_dir), containers, pool_name=args.pool_name, duration=args.duration, @@ -132,7 +132,7 @@ def main() -> None: of.tasks.create( helper.job.job_id, TaskType.generic_supervisor, - helper.target_exe_blob_name(args.target_exe, args.setup_dir), + helper.setup_relative_blob_name(args.target_exe, args.setup_dir), containers, pool_name=args.pool_name, supervisor_exe="/onefuzz/honggfuzz/honggfuzz", diff --git a/src/cli/onefuzz/templates/__init__.py b/src/cli/onefuzz/templates/__init__.py index e2b548d00..4b660833e 100644 --- a/src/cli/onefuzz/templates/__init__.py +++ b/src/cli/onefuzz/templates/__init__.py @@ -307,28 +307,30 @@ class JobHelper: wait_for_stopped=self.wait_for_stopped, ) - def target_exe_blob_name( - self, target_exe: File, setup_dir: Optional[Directory] + def setup_relative_blob_name( + self, local_file: File, setup_dir: Optional[Directory] ) -> str: - # The target executable must end up in the setup container, and the - # `target_exe` value passed to the tasks must be the name of the target - # exe _as a blob_ in the setup container. + # The local file must end up as a remote blob in the setup container. The blob + # name, which is a virtual `setup`-relative path, must be passed to the tasks as a + # value relative to the local copy of the setup directory. if setup_dir: - # If the user set a `setup_dir`, then `target_exe` must occur inside - # of it. When we upload the `setup_dir`, the blob name agrees with - # the `setup_dir`-relative path of the target. - resolved = os.path.relpath(target_exe, setup_dir) - if resolved.startswith("..") or resolved == target_exe: + # If we have a `setup_dir`, then `local_file` must occur inside of it. When we + # upload the `setup_dir`, the blob name will match the `setup_dir`-relative + # path to the file. + resolved = os.path.relpath(local_file, setup_dir) + + if resolved.startswith("..") or resolved == local_file: raise ValueError( - "target_exe (%s) is not within the setup directory (%s)" - % (target_exe, setup_dir) + "local file (%s) is not within the setup directory (%s)" + % (local_file, setup_dir) ) + return resolved else: - # If no `setup_dir` was given, we will upload `target_exe` to the - # root of the setup container created for the user. In that case, - # the `target_exe` name is just the filename of `target_exe`. - return os.path.basename(target_exe) + # If no `setup_dir` was given, we will upload the file at `local_file` to the + # root of the setup container created for the user. In that case, the future, + # setup-relative path to `local_file` is just the filename of `local_file`. + return os.path.basename(local_file) def add_tags(self, tags: Optional[Dict[str, str]]) -> None: if tags: diff --git a/src/cli/onefuzz/templates/afl.py b/src/cli/onefuzz/templates/afl.py index f2f36f731..936936078 100644 --- a/src/cli/onefuzz/templates/afl.py +++ b/src/cli/onefuzz/templates/afl.py @@ -116,7 +116,7 @@ class AFL(Command): ): raise Exception("AFL requires at least one input") - target_exe_blob_name = helper.target_exe_blob_name(target_exe, setup_dir) + target_exe_blob_name = helper.setup_relative_blob_name(target_exe, setup_dir) if afl_container is None: afl_container = Container( diff --git a/src/cli/onefuzz/templates/libfuzzer.py b/src/cli/onefuzz/templates/libfuzzer.py index cc895fd60..713ef7461 100644 --- a/src/cli/onefuzz/templates/libfuzzer.py +++ b/src/cli/onefuzz/templates/libfuzzer.py @@ -270,7 +270,7 @@ class Libfuzzer(Command): helper.upload_inputs(inputs) helper.wait_on(wait_for_files, wait_for_running) - target_exe_blob_name = helper.target_exe_blob_name(target_exe, setup_dir) + target_exe_blob_name = helper.setup_relative_blob_name(target_exe, setup_dir) self._create_tasks( job=helper.job, @@ -378,7 +378,7 @@ class Libfuzzer(Command): helper.upload_inputs(inputs) helper.wait_on(wait_for_files, wait_for_running) - target_exe_blob_name = helper.target_exe_blob_name(target_exe, setup_dir) + target_exe_blob_name = helper.setup_relative_blob_name(target_exe, setup_dir) merge_containers = [ (ContainerType.setup, helper.containers[ContainerType.setup]), @@ -619,7 +619,7 @@ class Libfuzzer(Command): helper.create_containers() - target_exe_blob_name = helper.target_exe_blob_name(target_exe, None) + target_exe_blob_name = helper.setup_relative_blob_name(target_exe, None) wrapper_name = File(target_exe_blob_name + "-wrapper.sh") @@ -627,7 +627,7 @@ class Libfuzzer(Command): if sysroot: setup_path = File(os.path.join(tempdir, "setup.sh")) with open(setup_path, "w", newline="\n") as handle: - sysroot_filename = helper.target_exe_blob_name(sysroot, None) + sysroot_filename = helper.setup_relative_blob_name(sysroot, None) handle.write( "#!/bin/bash\n" "set -ex\n" diff --git a/src/cli/onefuzz/templates/ossfuzz.py b/src/cli/onefuzz/templates/ossfuzz.py index b2dad4d03..a135f92e2 100644 --- a/src/cli/onefuzz/templates/ossfuzz.py +++ b/src/cli/onefuzz/templates/ossfuzz.py @@ -236,7 +236,7 @@ class OssFuzz(Command): # All fuzzers are copied to the setup container root. # # Cast because `glob()` returns `str`. - fuzzer_blob_name = helper.target_exe_blob_name(fuzzer, None) + fuzzer_blob_name = helper.setup_relative_blob_name(fuzzer, None) self.onefuzz.template.libfuzzer._create_tasks( job=base_helper.job, diff --git a/src/cli/onefuzz/templates/radamsa.py b/src/cli/onefuzz/templates/radamsa.py index 020dac917..2f06a6930 100644 --- a/src/cli/onefuzz/templates/radamsa.py +++ b/src/cli/onefuzz/templates/radamsa.py @@ -112,7 +112,7 @@ class Radamsa(Command): ): raise Exception("Radamsa requires at least one input file") - target_exe_blob_name = helper.target_exe_blob_name(target_exe, setup_dir) + target_exe_blob_name = helper.setup_relative_blob_name(target_exe, setup_dir) tools = Container( "radamsa-linux" if helper.platform == OS.linux else "radamsa-win64" diff --git a/src/cli/onefuzz/templates/regression.py b/src/cli/onefuzz/templates/regression.py index 2078ee075..0f931956c 100644 --- a/src/cli/onefuzz/templates/regression.py +++ b/src/cli/onefuzz/templates/regression.py @@ -239,7 +239,7 @@ class Regression(Command): helper.setup_notifications(notification_config) helper.upload_setup(setup_dir, target_exe) - target_exe_blob_name = helper.target_exe_blob_name(target_exe, setup_dir) + target_exe_blob_name = helper.setup_relative_blob_name(target_exe, setup_dir) self.logger.info("creating regression task") task = self.onefuzz.tasks.create( diff --git a/src/cli/tests/test_template_helper.py b/src/cli/tests/test_template_helper.py index 56dd256fe..d486989e3 100644 --- a/src/cli/tests/test_template_helper.py +++ b/src/cli/tests/test_template_helper.py @@ -63,10 +63,10 @@ class TestHelper(unittest.TestCase): values[(filename, Directory("c:\\unused\\"))] = expected for (args, expected) in values.items(): - self.assertEqual(helper.target_exe_blob_name(*args), expected) + self.assertEqual(helper.setup_relative_blob_name(*args), expected) with self.assertRaises(ValueError): - helper.target_exe_blob_name( + helper.setup_relative_blob_name( File("dir/filename.txt"), Directory("other_dir") )