Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit b49d140

Browse files
authored
Add fuzzer_target_options to libfuzzer basic template (#1610)
1 parent 6100191 commit b49d140

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

src/cli/onefuzz/templates/libfuzzer.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def _create_tasks(
4949
duration: int = 24,
5050
target_workers: Optional[int] = None,
5151
target_options: Optional[List[str]] = None,
52+
fuzzing_target_options: Optional[List[str]] = None,
5253
target_env: Optional[Dict[str, str]] = None,
5354
target_timeout: Optional[int] = None,
5455
tags: Optional[Dict[str, str]] = None,
@@ -63,6 +64,7 @@ def _create_tasks(
6364
minimized_stack_depth: Optional[int] = None,
6465
coverage_filter: Optional[str] = None,
6566
) -> None:
67+
target_options = target_options or []
6668

6769
regression_containers = [
6870
(ContainerType.setup, containers[ContainerType.setup]),
@@ -121,6 +123,15 @@ def _create_tasks(
121123
if ensemble_sync_delay is None and vm_count == 1:
122124
ensemble_sync_delay = 0
123125

126+
# Build `target_options` for the `libfuzzer_fuzz` task.
127+
#
128+
# This allows passing arguments like `-runs` to the target only when
129+
# invoked in persistent fuzzing mode, and not test case repro mode.
130+
libfuzzer_fuzz_target_options = target_options.copy()
131+
132+
if fuzzing_target_options:
133+
libfuzzer_fuzz_target_options += fuzzing_target_options
134+
124135
fuzzer_task = self.onefuzz.tasks.create(
125136
job.job_id,
126137
TaskType.libfuzzer_fuzz,
@@ -130,7 +141,7 @@ def _create_tasks(
130141
reboot_after_setup=reboot_after_setup,
131142
duration=duration,
132143
vm_count=vm_count,
133-
target_options=target_options,
144+
target_options=libfuzzer_fuzz_target_options,
134145
target_env=target_env,
135146
target_workers=target_workers,
136147
tags=tags,
@@ -236,6 +247,7 @@ def basic(
236247
duration: int = 24,
237248
target_workers: Optional[int] = None,
238249
target_options: Optional[List[str]] = None,
250+
fuzzing_target_options: Optional[List[str]] = None,
239251
target_env: Optional[Dict[str, str]] = None,
240252
target_timeout: Optional[int] = None,
241253
check_retry_count: Optional[int] = None,
@@ -340,6 +352,7 @@ def basic(
340352
duration=duration,
341353
target_workers=target_workers,
342354
target_options=target_options,
355+
fuzzing_target_options=fuzzing_target_options,
343356
target_env=target_env,
344357
tags=helper.tags,
345358
crash_report_timeout=crash_report_timeout,
@@ -494,6 +507,7 @@ def dotnet(
494507
duration: int = 24,
495508
target_workers: Optional[int] = None,
496509
target_options: Optional[List[str]] = None,
510+
fuzzing_target_options: Optional[List[str]] = None,
497511
target_env: Optional[Dict[str, str]] = None,
498512
tags: Optional[Dict[str, str]] = None,
499513
wait_for_running: bool = False,
@@ -567,6 +581,15 @@ def dotnet(
567581
helper.upload_inputs(inputs)
568582
helper.wait_on(wait_for_files, wait_for_running)
569583

584+
# Build `target_options` for the `libfuzzer_fuzz` task.
585+
#
586+
# This allows passing arguments like `-runs` to the target only when
587+
# invoked in persistent fuzzing mode, and not test case repro mode.
588+
libfuzzer_fuzz_target_options = target_options.copy()
589+
590+
if fuzzing_target_options:
591+
libfuzzer_fuzz_target_options += fuzzing_target_options
592+
570593
self.onefuzz.tasks.create(
571594
helper.job.job_id,
572595
TaskType.libfuzzer_fuzz,
@@ -576,7 +599,7 @@ def dotnet(
576599
reboot_after_setup=reboot_after_setup,
577600
duration=duration,
578601
vm_count=vm_count,
579-
target_options=target_options,
602+
target_options=libfuzzer_fuzz_target_options,
580603
target_env=target_env,
581604
target_workers=target_workers,
582605
tags=tags,
@@ -606,6 +629,7 @@ def qemu_user(
606629
duration: int = 24,
607630
target_workers: Optional[int] = 1,
608631
target_options: Optional[List[str]] = None,
632+
fuzzing_target_options: Optional[List[str]] = None,
609633
target_env: Optional[Dict[str, str]] = None,
610634
tags: Optional[Dict[str, str]] = None,
611635
wait_for_running: bool = False,
@@ -729,6 +753,15 @@ def qemu_user(
729753
helper.upload_inputs(inputs)
730754
helper.wait_on(wait_for_files, wait_for_running)
731755

756+
# Build `target_options` for the `libfuzzer_fuzz` task.
757+
#
758+
# This allows passing arguments like `-runs` to the target only when
759+
# invoked in persistent fuzzing mode, and not test case repro mode.
760+
libfuzzer_fuzz_target_options = target_options.copy()
761+
762+
if fuzzing_target_options:
763+
libfuzzer_fuzz_target_options += fuzzing_target_options
764+
732765
self.logger.info("creating libfuzzer_fuzz task")
733766
fuzzer_task = self.onefuzz.tasks.create(
734767
helper.job.job_id,
@@ -739,7 +772,7 @@ def qemu_user(
739772
reboot_after_setup=reboot_after_setup,
740773
duration=duration,
741774
vm_count=vm_count,
742-
target_options=target_options,
775+
target_options=libfuzzer_fuzz_target_options,
743776
target_env=target_env,
744777
target_workers=target_workers,
745778
tags=tags,

0 commit comments

Comments
 (0)