mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-17 12:28:07 +00:00
Rename helper method for setup-relative files (#926)
We are going to use this for more than just target exes, and in fact, it applies to any file that must occur in the setup directory/container.
This commit is contained in:
@ -156,7 +156,7 @@ def main() -> None:
|
|||||||
of.tasks.create(
|
of.tasks.create(
|
||||||
helper.job.job_id,
|
helper.job.job_id,
|
||||||
TaskType.generic_crash_report,
|
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,
|
containers,
|
||||||
pool_name=args.pool_name,
|
pool_name=args.pool_name,
|
||||||
duration=args.duration,
|
duration=args.duration,
|
||||||
@ -201,7 +201,7 @@ def main() -> None:
|
|||||||
of.tasks.create(
|
of.tasks.create(
|
||||||
helper.job.job_id,
|
helper.job.job_id,
|
||||||
TaskType.generic_generator,
|
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,
|
containers,
|
||||||
pool_name=args.pool_name,
|
pool_name=args.pool_name,
|
||||||
target_options=target_command,
|
target_options=target_command,
|
||||||
|
@ -101,7 +101,7 @@ def main() -> None:
|
|||||||
of.tasks.create(
|
of.tasks.create(
|
||||||
helper.job.job_id,
|
helper.job.job_id,
|
||||||
TaskType.generic_crash_report,
|
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,
|
containers,
|
||||||
pool_name=args.pool_name,
|
pool_name=args.pool_name,
|
||||||
duration=args.duration,
|
duration=args.duration,
|
||||||
@ -132,7 +132,7 @@ def main() -> None:
|
|||||||
of.tasks.create(
|
of.tasks.create(
|
||||||
helper.job.job_id,
|
helper.job.job_id,
|
||||||
TaskType.generic_supervisor,
|
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,
|
containers,
|
||||||
pool_name=args.pool_name,
|
pool_name=args.pool_name,
|
||||||
supervisor_exe="/onefuzz/honggfuzz/honggfuzz",
|
supervisor_exe="/onefuzz/honggfuzz/honggfuzz",
|
||||||
|
@ -307,28 +307,30 @@ class JobHelper:
|
|||||||
wait_for_stopped=self.wait_for_stopped,
|
wait_for_stopped=self.wait_for_stopped,
|
||||||
)
|
)
|
||||||
|
|
||||||
def target_exe_blob_name(
|
def setup_relative_blob_name(
|
||||||
self, target_exe: File, setup_dir: Optional[Directory]
|
self, local_file: File, setup_dir: Optional[Directory]
|
||||||
) -> str:
|
) -> str:
|
||||||
# The target executable must end up in the setup container, and the
|
# The local file must end up as a remote blob in the setup container. The blob
|
||||||
# `target_exe` value passed to the tasks must be the name of the target
|
# name, which is a virtual `setup`-relative path, must be passed to the tasks as a
|
||||||
# exe _as a blob_ in the setup container.
|
# value relative to the local copy of the setup directory.
|
||||||
if setup_dir:
|
if setup_dir:
|
||||||
# If the user set a `setup_dir`, then `target_exe` must occur inside
|
# If we have a `setup_dir`, then `local_file` must occur inside of it. When we
|
||||||
# of it. When we upload the `setup_dir`, the blob name agrees with
|
# upload the `setup_dir`, the blob name will match the `setup_dir`-relative
|
||||||
# the `setup_dir`-relative path of the target.
|
# path to the file.
|
||||||
resolved = os.path.relpath(target_exe, setup_dir)
|
resolved = os.path.relpath(local_file, setup_dir)
|
||||||
if resolved.startswith("..") or resolved == target_exe:
|
|
||||||
|
if resolved.startswith("..") or resolved == local_file:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"target_exe (%s) is not within the setup directory (%s)"
|
"local file (%s) is not within the setup directory (%s)"
|
||||||
% (target_exe, setup_dir)
|
% (local_file, setup_dir)
|
||||||
)
|
)
|
||||||
|
|
||||||
return resolved
|
return resolved
|
||||||
else:
|
else:
|
||||||
# If no `setup_dir` was given, we will upload `target_exe` to the
|
# 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,
|
# root of the setup container created for the user. In that case, the future,
|
||||||
# the `target_exe` name is just the filename of `target_exe`.
|
# setup-relative path to `local_file` is just the filename of `local_file`.
|
||||||
return os.path.basename(target_exe)
|
return os.path.basename(local_file)
|
||||||
|
|
||||||
def add_tags(self, tags: Optional[Dict[str, str]]) -> None:
|
def add_tags(self, tags: Optional[Dict[str, str]]) -> None:
|
||||||
if tags:
|
if tags:
|
||||||
|
@ -116,7 +116,7 @@ class AFL(Command):
|
|||||||
):
|
):
|
||||||
raise Exception("AFL requires at least one input")
|
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:
|
if afl_container is None:
|
||||||
afl_container = Container(
|
afl_container = Container(
|
||||||
|
@ -270,7 +270,7 @@ class Libfuzzer(Command):
|
|||||||
helper.upload_inputs(inputs)
|
helper.upload_inputs(inputs)
|
||||||
helper.wait_on(wait_for_files, wait_for_running)
|
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(
|
self._create_tasks(
|
||||||
job=helper.job,
|
job=helper.job,
|
||||||
@ -378,7 +378,7 @@ class Libfuzzer(Command):
|
|||||||
helper.upload_inputs(inputs)
|
helper.upload_inputs(inputs)
|
||||||
helper.wait_on(wait_for_files, wait_for_running)
|
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 = [
|
merge_containers = [
|
||||||
(ContainerType.setup, helper.containers[ContainerType.setup]),
|
(ContainerType.setup, helper.containers[ContainerType.setup]),
|
||||||
@ -619,7 +619,7 @@ class Libfuzzer(Command):
|
|||||||
|
|
||||||
helper.create_containers()
|
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")
|
wrapper_name = File(target_exe_blob_name + "-wrapper.sh")
|
||||||
|
|
||||||
@ -627,7 +627,7 @@ class Libfuzzer(Command):
|
|||||||
if sysroot:
|
if sysroot:
|
||||||
setup_path = File(os.path.join(tempdir, "setup.sh"))
|
setup_path = File(os.path.join(tempdir, "setup.sh"))
|
||||||
with open(setup_path, "w", newline="\n") as handle:
|
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(
|
handle.write(
|
||||||
"#!/bin/bash\n"
|
"#!/bin/bash\n"
|
||||||
"set -ex\n"
|
"set -ex\n"
|
||||||
|
@ -236,7 +236,7 @@ class OssFuzz(Command):
|
|||||||
# All fuzzers are copied to the setup container root.
|
# All fuzzers are copied to the setup container root.
|
||||||
#
|
#
|
||||||
# Cast because `glob()` returns `str`.
|
# 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(
|
self.onefuzz.template.libfuzzer._create_tasks(
|
||||||
job=base_helper.job,
|
job=base_helper.job,
|
||||||
|
@ -112,7 +112,7 @@ class Radamsa(Command):
|
|||||||
):
|
):
|
||||||
raise Exception("Radamsa requires at least one input file")
|
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(
|
tools = Container(
|
||||||
"radamsa-linux" if helper.platform == OS.linux else "radamsa-win64"
|
"radamsa-linux" if helper.platform == OS.linux else "radamsa-win64"
|
||||||
|
@ -239,7 +239,7 @@ class Regression(Command):
|
|||||||
helper.setup_notifications(notification_config)
|
helper.setup_notifications(notification_config)
|
||||||
|
|
||||||
helper.upload_setup(setup_dir, target_exe)
|
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")
|
self.logger.info("creating regression task")
|
||||||
task = self.onefuzz.tasks.create(
|
task = self.onefuzz.tasks.create(
|
||||||
|
@ -63,10 +63,10 @@ class TestHelper(unittest.TestCase):
|
|||||||
values[(filename, Directory("c:\\unused\\"))] = expected
|
values[(filename, Directory("c:\\unused\\"))] = expected
|
||||||
|
|
||||||
for (args, expected) in values.items():
|
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):
|
with self.assertRaises(ValueError):
|
||||||
helper.target_exe_blob_name(
|
helper.setup_relative_blob_name(
|
||||||
File("dir/filename.txt"), Directory("other_dir")
|
File("dir/filename.txt"), Directory("other_dir")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user