Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: enable using FI against projects without harnesses #1930

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/fuzz_introspector/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def load_data_files(self, parallelise=True, correlation_file=None):
self.profiles = new_profiles

logger.info("[+] Creating project profile")
self.proj_profile = project_profile.MergedProjectProfile(self.profiles)
self.proj_profile = project_profile.MergedProjectProfile(
self.profiles, self.language)
self.proj_profile.coverage_url = self.coverage_url

logger.info("[+] Refining profiles")
Expand Down
6 changes: 3 additions & 3 deletions src/fuzz_introspector/data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def read_fuzzer_data_file_to_profile(

if not profile.has_entry_point():
logger.info("Found no entrypoints")
return None

logger.info("Returning profile")
return profile

Expand All @@ -80,10 +80,10 @@ def _load_profile(data_file: str, language: str, manager, semaphore=None):
semaphore.acquire()

profile = read_fuzzer_data_file_to_profile(data_file, language)
logger.info('profile is none')
if profile is not None:
manager[data_file] = profile

else:
logger.error('profile is none')
if semaphore is not None:
semaphore.release()

Expand Down
4 changes: 2 additions & 2 deletions src/fuzz_introspector/datatypes/fuzzer_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def __init__(self,
self._target_lang = target_lang
self.introspector_data_file = cfg_file

self.functions_reached_by_fuzzer: List[str] = []

# Load calltree file
self.fuzzer_callsite_calltree = cfg_load.data_file_read_calltree(
cfg_file)
Expand Down Expand Up @@ -494,8 +496,6 @@ def _set_all_reached_functions(self) -> None:
self.functions_reached_by_fuzzer.append(entrypoint)
return

raise DataLoaderError("Can not identify entrypoint")

def _set_all_unreached_functions(self) -> None:
"""Sets self.functions_unreached_by_fuzzer to all functions that are
statically unreached. This is computed as the set difference between
Expand Down
6 changes: 5 additions & 1 deletion src/fuzz_introspector/datatypes/project_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class MergedProjectProfile:
digesting data from all the fuzzers in the project.
"""

def __init__(self, profiles: List[fuzzer_profile.FuzzerProfile]):
def __init__(self, profiles: List[fuzzer_profile.FuzzerProfile],
language: str):
self.name = None
self.profiles = profiles
self.all_functions: Dict[str,
Expand All @@ -49,6 +50,7 @@ def __init__(self, profiles: List[fuzzer_profile.FuzzerProfile]):
self.coverage_url = "#"
self.dst_to_fd_cache: Dict[str,
function_profile.FunctionProfile] = dict()
self.language = language

logger.info(
f"Creating merged profile of {len(self.profiles)} profiles")
Expand Down Expand Up @@ -230,6 +232,8 @@ def target_lang(self):
if len(set_of_targets) > 1:
raise exceptions.AnalysisError(
"Project has fuzzers with multiple targets")
if not set_of_targets:
return self.language
return set_of_targets.pop()

@property
Expand Down
10 changes: 10 additions & 0 deletions src/fuzz_introspector/frontends/oss_fuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ def process_c_project(target_dir, entrypoint, out, module_only=False):
logger.info('Creating base project.')
project = frontend_c.Project(source_codes)

# We may not need to do this, but will do it while refactoring into
# the new frontends.
if not project.get_source_codes_with_harnesses():
target = os.path.join(out, 'fuzzerLogFile-0.data.yaml')
project.dump_module_logic(target, 'no-harness-in-project', target_dir)

with open(os.path.join(out, 'fuzzerLogFile-0.data'), 'w') as f:
f.write("Call tree\n")
f.write("====================================")

if module_only:
idx = 1
target = os.path.join(out, 'report.yaml')
Expand Down
Loading