Skip to content

Commit 3ba9700

Browse files
core: add ability to specify output directory (#1976)
* core: add ability to specify output directory Signed-off-by: David Korczynski <david@adalogics.com> * nit Signed-off-by: David Korczynski <david@adalogics.com> * nit Signed-off-by: David Korczynski <david@adalogics.com> * nit Signed-off-by: David Korczynski <david@adalogics.com> * nit Signed-off-by: David Korczynski <david@adalogics.com> --------- Signed-off-by: David Korczynski <david@adalogics.com>
1 parent 79eb8e1 commit 3ba9700

20 files changed

+189
-124
lines changed

src/fuzz_introspector/analyses/annotated_cfg.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def analysis_func(self,
5454
proj_profile: project_profile.MergedProjectProfile,
5555
profiles: List[fuzzer_profile.FuzzerProfile],
5656
basefolder: str, coverage_url: str,
57-
conclusions: List[html_helpers.HTMLConclusion]) -> str:
57+
conclusions: List[html_helpers.HTMLConclusion],
58+
out_dir: str) -> str:
5859
"""
5960
Creates the HTML of the calltree. Returns the HTML as a string.
6061
"""
@@ -142,7 +143,7 @@ def analysis_func(self,
142143

143144
# Write the results to the json report
144145
json_report.add_analysis_json_str_as_dict_to_report(
145-
self.get_name(), self.get_json_string_result())
146+
self.get_name(), self.get_json_string_result(), out_dir)
146147
return ""
147148

148149
def get_profile_sourcefile(self, profile, func_name):

src/fuzz_introspector/analyses/bug_digestor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def analysis_func(self,
5353
proj_profile: project_profile.MergedProjectProfile,
5454
profiles: List[fuzzer_profile.FuzzerProfile],
5555
basefolder: str, coverage_url: str,
56-
conclusions: List[html_helpers.HTMLConclusion]) -> str:
56+
conclusions: List[html_helpers.HTMLConclusion],
57+
out_dir) -> str:
5758
"""Digests and creates HTML about bugs found by the fuzzers."""
5859
logger.info(f" - Running analysis {self.get_name()}")
5960
input_bugs = data_loader.try_load_input_bugs()

src/fuzz_introspector/analyses/calltree_analysis.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def analysis_func(self,
6262
proj_profile: project_profile.MergedProjectProfile,
6363
profiles: List[fuzzer_profile.FuzzerProfile],
6464
basefolder: str, coverage_url: str,
65-
conclusions: List[html_helpers.HTMLConclusion]) -> str:
65+
conclusions: List[html_helpers.HTMLConclusion],
66+
out_dir) -> str:
6667
"""
6768
Creates the HTML of the calltree. Returns the HTML as a string.
6869
"""
@@ -88,7 +89,8 @@ def _get_span_row(self, ct_idx_str, indentation, node, demangled_name,
8889
</span>"""
8990
return span_row
9091

91-
def create_calltree(self, profile: fuzzer_profile.FuzzerProfile) -> str:
92+
def create_calltree(self, profile: fuzzer_profile.FuzzerProfile,
93+
out_dir) -> str:
9294
logger.info("In calltree")
9395
# Generate HTML for the calltree
9496
calltree_html_string = "<h1>Fuzzer calltree</h1>"
@@ -190,10 +192,12 @@ def create_calltree(self, profile: fuzzer_profile.FuzzerProfile) -> str:
190192

191193
# Write the HTML to a file called calltree_view_XX.html where XX is a counter.
192194
calltree_file_idx = 0
193-
calltree_html_file = f"calltree_view_{calltree_file_idx}.html"
195+
calltree_html_file = os.path.join(
196+
out_dir, f"calltree_view_{calltree_file_idx}.html")
194197
while os.path.isfile(calltree_html_file):
195198
calltree_file_idx += 1
196-
calltree_html_file = f"calltree_view_{calltree_file_idx}.html"
199+
calltree_html_file = os.path.join(
200+
out_dir, f"calltree_view_{calltree_file_idx}.html")
197201

198202
self.html_create_dedicated_calltree_file(
199203
calltree_html_string,

src/fuzz_introspector/analyses/driver_synthesizer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def analysis_func(self,
6363
basefolder: str,
6464
coverage_url: str,
6565
conclusions: List[html_helpers.HTMLConclusion],
66+
out_dir,
6667
fuzz_targets=None) -> str:
6768
logger.info(f" - Running analysis {self.get_name()}")
6869
html_string = ""

src/fuzz_introspector/analyses/engine_input.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def analysis_func(self,
5353
project_profile: project_profile.MergedProjectProfile,
5454
profiles: List[fuzzer_profile.FuzzerProfile],
5555
basefolder: str, coverage_url: str,
56-
conclusions: List[html_helpers.HTMLConclusion]) -> str:
56+
conclusions: List[html_helpers.HTMLConclusion],
57+
out_dir) -> str:
5758
logger.info(f" - Running analysis {self.get_name()}")
5859

5960
if not self.display_html:
@@ -80,7 +81,8 @@ def analysis_func(self,
8081

8182
# Create dictionary section
8283
html_string += self.get_dictionary_section(profiles[profile_idx],
83-
table_of_contents)
84+
table_of_contents,
85+
out_dir)
8486

8587
html_string += "<br>"
8688

@@ -98,7 +100,8 @@ def analysis_func(self,
98100

99101
return html_string
100102

101-
def get_dictionary(self, profile: fuzzer_profile.FuzzerProfile) -> str:
103+
def get_dictionary(self, profile: fuzzer_profile.FuzzerProfile,
104+
out_dir) -> str:
102105
"""Extracts a fuzzer dictionary"""
103106
kn = 0
104107
dictionary_content = ""
@@ -118,12 +121,13 @@ def get_dictionary(self, profile: fuzzer_profile.FuzzerProfile) -> str:
118121
kn += 1
119122
self.set_json_string_result(json.dumps(dictionary))
120123
json_report.add_analysis_json_str_as_dict_to_report(
121-
self.get_name(), self.get_json_string_result())
124+
self.get_name(), self.get_json_string_result(), out_dir)
122125
return dictionary_content
123126

124127
def get_dictionary_section(
125128
self, profile: fuzzer_profile.FuzzerProfile,
126-
table_of_contents: html_helpers.HtmlTableOfContents) -> str:
129+
table_of_contents: html_helpers.HtmlTableOfContents,
130+
out_dir) -> str:
127131
"""
128132
Returns a HTML string with dictionary content, and adds the section
129133
link to the table_of_contents.
@@ -133,7 +137,7 @@ def get_dictionary_section(
133137
"Dictionary", html_helpers.HTML_HEADING.H3, table_of_contents)
134138
html_string += "<p>Use this with the libFuzzer -dict=DICT.file flag</p>"
135139
html_string += "<pre><code class='language-clike'>"
136-
html_string += self.get_dictionary(profile)
140+
html_string += self.get_dictionary(profile, out_dir)
137141
html_string += "</code></pre>"
138142
return html_string
139143

src/fuzz_introspector/analyses/filepath_analyser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def analysis_func(self,
5656
proj_profile: project_profile.MergedProjectProfile,
5757
profiles: List[fuzzer_profile.FuzzerProfile],
5858
basefolder: str, coverage_url: str,
59-
conclusions: List[html_helpers.HTMLConclusion]) -> str:
59+
conclusions: List[html_helpers.HTMLConclusion],
60+
out_dir) -> str:
6061
logger.info(f" - Running analysis {self.get_name()}")
6162

6263
all_proj_files = self.all_files_targeted(proj_profile)

src/fuzz_introspector/analyses/function_call_analyser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ def analysis_func(self,
146146
proj_profile: project_profile.MergedProjectProfile,
147147
profiles: List[fuzzer_profile.FuzzerProfile],
148148
basefolder: str, coverage_url: str,
149-
conclusions: List[html_helpers.HTMLConclusion]) -> str:
149+
conclusions: List[html_helpers.HTMLConclusion],
150+
out_dir) -> str:
150151
"""
151152
Performs an analysis for all third party API call in the target project.
152153
Finds the set of third party API call in the project code and provide

src/fuzz_introspector/analyses/metadata.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def analysis_func(self,
5151
project_profile: project_profile.MergedProjectProfile,
5252
profiles: List[fuzzer_profile.FuzzerProfile],
5353
basefolder: str, coverage_url: str,
54-
conclusions: List[html_helpers.HTMLConclusion]) -> str:
54+
conclusions: List[html_helpers.HTMLConclusion],
55+
out_dir) -> str:
5556
logger.info(f" - Running analysis {self.get_name()}")
5657

5758
html_string = ""

src/fuzz_introspector/analyses/optimal_targets.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def analysis_func(self,
133133
basefolder: str,
134134
coverage_url: str,
135135
conclusions: List[html_helpers.HTMLConclusion],
136+
out_dir,
136137
should_synthetise: bool = False) -> str:
137138
"""
138139
Performs an analysis based on optimal target selection.
@@ -161,7 +162,7 @@ def analysis_func(self,
161162
proj_profile)
162163
html_string += self.get_optimal_target_section(
163164
optimal_target_functions, table_of_contents, tables, coverage_url,
164-
profiles[0].target_lang)
165+
out_dir, profiles[0].target_lang)
165166

166167
# Create section for how the state of the project will be if
167168
# the optimal target functions are hit.
@@ -290,6 +291,7 @@ def get_optimal_target_section(
290291
table_of_contents: html_helpers.HtmlTableOfContents,
291292
tables: List[str],
292293
coverage_url: str,
294+
out_dir,
293295
target_lang: str = 'c-cpp') -> str:
294296
# Table with details about optimal target functions
295297
html_string = html_helpers.html_add_header_with_link(
@@ -349,7 +351,7 @@ def get_optimal_target_section(
349351
self.set_json_string_result(json.dumps(json_dict))
350352

351353
json_report.add_analysis_json_str_as_dict_to_report(
352-
self.get_name(), self.get_json_string_result())
354+
self.get_name(), self.get_json_string_result(), out_dir)
353355
html_string += ("</table>\n")
354356
return html_string
355357

src/fuzz_introspector/analyses/runtime_coverage_analysis.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def analysis_func(self,
4949
proj_profile: project_profile.MergedProjectProfile,
5050
profiles: List[fuzzer_profile.FuzzerProfile],
5151
basefolder: str, coverage_url: str,
52-
conclusions: List[html_helpers.HTMLConclusion]) -> str:
52+
conclusions: List[html_helpers.HTMLConclusion],
53+
out_dir) -> str:
5354
logger.info(f" - Running analysis {self.get_name()}")
5455

5556
html_string = ""

0 commit comments

Comments
 (0)