Skip to content
This repository was archived by the owner on Apr 30, 2021. It is now read-only.

Commit 9825bee

Browse files
committed
Add support for --runs
This options allows to limit the number of fuzzing rounds.
1 parent 858683f commit 9825bee

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

pythonfuzz/fuzzer.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def __init__(self,
7979
timeout=120,
8080
regression=False,
8181
max_input_size=4096,
82-
close_fd_mask=0):
82+
close_fd_mask=0,
83+
runs=-1):
8384
self._target = target
8485
self._dirs = [] if dirs is None else dirs
8586
self._exact_artifact_path = exact_artifact_path
@@ -93,6 +94,7 @@ def __init__(self,
9394
self._last_sample_time = time.time()
9495
self._total_coverage = 0
9596
self._p = None
97+
self.runs = runs
9698

9799
def log_stats(self, log_type):
98100
rss = (psutil.Process(self._p.pid).memory_info().rss + psutil.Process(os.getpid()).memory_info().rss) / 1024 / 1024
@@ -125,8 +127,12 @@ def start(self):
125127
self._p = mp.Process(target=worker, args=(self._target, child_conn, self._close_fd_mask))
126128
self._p.start()
127129

128-
129130
while True:
131+
if self.runs != -1 and self._total_executions >= self.runs:
132+
self._p.terminate()
133+
logging.info('did %d runs, stopping now.', self.runs)
134+
break
135+
130136
buf = self._corpus.generate_input()
131137
parent_conn.send_bytes(buf)
132138
if not parent_conn.poll(self._timeout):

pythonfuzz/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ def __call__(self, *args, **kwargs):
2121
parser.add_argument('--rss-limit-mb', type=int, default=2048, help='Memory usage in MB')
2222
parser.add_argument('--max-input-size', type=int, default=4096, help='Max input size in bytes')
2323
parser.add_argument('--close-fd-mask', type=int, default=0, help='Indicate output streams to close at startup')
24+
parser.add_argument('--runs', type=int, default=-1, help='Number of individual test runs, -1 (the default) to run indefinitely.')
2425
parser.add_argument('--timeout', type=int, default=30,
2526
help='If input takes longer then this timeout the process is treated as failure case')
2627
args = parser.parse_args()
2728
f = fuzzer.Fuzzer(self.function, args.dirs, args.exact_artifact_path,
2829
args.rss_limit_mb, args.timeout, args.regression, args.max_input_size,
29-
args.close_fd_mask)
30+
args.close_fd_mask, args.runs)
3031
f.start()
3132

3233

0 commit comments

Comments
 (0)