From 22a2d5d376069d5975f0b8b21f1ea5173df0b6f2 Mon Sep 17 00:00:00 2001 From: Jonathan Metzman Date: Thu, 31 Oct 2024 13:57:42 -0400 Subject: [PATCH] Refactor fuzzingsession --- .../_internal/bot/tasks/utasks/fuzz_task.py | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/clusterfuzz/_internal/bot/tasks/utasks/fuzz_task.py b/src/clusterfuzz/_internal/bot/tasks/utasks/fuzz_task.py index 4b22d1059e..eb06e5414f 100644 --- a/src/clusterfuzz/_internal/bot/tasks/utasks/fuzz_task.py +++ b/src/clusterfuzz/_internal/bot/tasks/utasks/fuzz_task.py @@ -1482,6 +1482,13 @@ def generate_blackbox_testcases( def do_engine_fuzzing(self, engine_impl): """Run fuzzing engine.""" + # Centipede requires separate binaries for sanitized targets. + if environment.is_centipede_fuzzer_job(): + sanitized_target_bucket_path = environment.get_value( + 'SANITIZED_TARGET_BUILD_BUCKET_PATH') + if sanitized_target_bucket_path: + logs.error('Failed to set up sanitized_target_build.') + environment.set_value('FUZZER_NAME', self.fuzz_target.fully_qualified_name()) @@ -1716,9 +1723,7 @@ def do_blackbox_fuzzing(self, fuzzer, fuzzer_directory, job_type): return (generate_result.fuzzer_metadata, testcase_file_paths, testcases_metadata, crashes) - def run(self): - """Run the fuzzing session.""" - start_time = time.time() + def run_common(self): # Update LSAN local blacklist with global blacklist. global_blacklisted_functions = ( self.uworker_input.fuzz_task_input.global_blacklisted_functions) @@ -1737,11 +1742,21 @@ def run(self): # is using command override for task execution. failure_wait_interval = environment.get_value('FAIL_WAIT') time.sleep(failure_wait_interval) - return uworker_msg_pb2.Output( # pylint: disable=no-member + return uworker_msg_pb2.Output( # pylint: disable=no-memberp error_type=uworker_msg_pb2.ErrorType.FUZZ_NO_FUZZER) # pylint: disable=no-member self.testcase_directory = environment.get_value('FUZZ_INPUTS') + return None + def run(self): + """Run the fuzzing session.""" + start_time = time.time() + result = self._run_common() + if result: + return result + + # TODO(metzman): Move this section into seperate functions for engine and + # blackbox fuzzing instead of sandwhiching with ifs for engine fuzzing. fuzz_target = self.fuzz_target.binary if self.fuzz_target else None build_setup_result = build_manager.setup_build( environment.get_value('APP_REVISION'), fuzz_target=fuzz_target) @@ -1765,13 +1780,6 @@ def run(self): return uworker_msg_pb2.Output( # pylint: disable=no-member error_type=uworker_msg_pb2.ErrorType.FUZZ_BUILD_SETUP_FAILURE) # pylint: disable=no-member - # Centipede requires separate binaries for sanitized targets. - if environment.is_centipede_fuzzer_job(): - sanitized_target_bucket_path = environment.get_value( - 'SANITIZED_TARGET_BUILD_BUCKET_PATH') - if sanitized_target_bucket_path: - logs.error('Failed to set up sanitized_target_build.') - # Check if we have a bad build, i.e. one that crashes on startup. # If yes, bail out. logs.info('Checking for bad build.')