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: harden analysis against projects without fuzzers #1503

Merged
merged 1 commit into from
Apr 11, 2024
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
32 changes: 25 additions & 7 deletions src/fuzz_introspector/datatypes/project_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,17 @@ def get_function_summaries(self) -> Tuple[int, int, int, float, float]:
reached_func_count = self._get_total_reached_function_count()
unreached_func_count = self._get_total_unreached_function_count()
total_functions = reached_func_count + unreached_func_count
reached_percentage = (float(reached_func_count) /
float(total_functions)) * 100
unreached_percentage = (float(unreached_func_count) /
float(total_functions)) * 100
try:
reached_percentage = (float(reached_func_count) /
float(total_functions)) * 100
except ZeroDivisionError:
reached_percentage = 0.0

try:
unreached_percentage = (float(unreached_func_count) /
float(total_functions)) * 100
except ZeroDivisionError:
unreached_percentage = 0.0
return (total_functions, reached_func_count, unreached_func_count,
reached_percentage, unreached_percentage)

Expand Down Expand Up @@ -273,8 +280,11 @@ def reached_func_percentage(self):
reached_func_count = self._get_total_reached_function_count()
unreached_func_count = self._get_total_unreached_function_count()
total_functions = reached_func_count + unreached_func_count
reached_percentage = (float(reached_func_count) /
float(total_functions)) * 100
try:
reached_percentage = (float(reached_func_count) /
float(total_functions)) * 100
except ZeroDivisionError:
reached_percentage = 0.0
return reached_percentage

def get_profiles_coverage_files(self) -> List[str]:
Expand Down Expand Up @@ -377,7 +387,11 @@ def write_stats_to_summary_file(self) -> None:
unreached_func_percentage) = self.get_function_summaries()

covered_funcs = self.get_all_runtime_covered_functions()
cov_percentage = round(len(covered_funcs) / total_functions, 2) * 100.0
try:
cov_percentage = round(len(covered_funcs) / total_functions,
2) * 100.0
except ZeroDivisionError:
cov_percentage = 0.0

json_report.add_project_key_value_to_report(
"stats", {
Expand Down Expand Up @@ -411,6 +425,10 @@ def _set_basefolder(self) -> None:
continue
all_strs.append(os.path.dirname(f.function_source_file))

if len(all_strs) == 0:
self.basefolder = ""
return

self.basefolder = utils.longest_common_prefix(all_strs) + "/"

def _get_total_unreached_function_count(self) -> int:
Expand Down
6 changes: 5 additions & 1 deletion src/fuzz_introspector/html_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,11 @@ def create_percentage_graph(title: str, numerator: int,
"""Creates a percentage tag within a <div> tag. This is used to show
"how much X is of Y" for a {numerator, denominator} pair.
"""
percentage = round(float(numerator) / float(denominator), 2) * 100.0
try:
percentage = round(float(numerator) / float(denominator), 2) * 100.0
except ZeroDivisionError:
percentage = 0.0

subtitle = f"{numerator} / {denominator}"
return f"""<div style="flex:1; margin-right: 20px"class="report-box mt-0">
<div style="font-weight: 600; text-align: center;">
Expand Down
7 changes: 5 additions & 2 deletions src/fuzz_introspector/html_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,11 @@ def create_boxed_top_summary_info(
title="No coverage data was found",
description=html_constants.WARNING_NO_COVERAGE))
# Add coverage conclusion
coverage_percentage = float(
len(covered_funcs) / float(proj_profile.total_functions) * 100.0)
try:
coverage_percentage = float(
len(covered_funcs) / float(proj_profile.total_functions) * 100.0)
except ZeroDivisionError:
coverage_percentage = 0.0
if coverage_percentage > 50.0:
sentence = f"""Fuzzers reach {"%.5s%%"%(str(coverage_percentage))} code coverage."""
conclusions.append(
Expand Down
Loading