Skip to content

Commit 34f7682

Browse files
committed
fix logic
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
1 parent e96d4ee commit 34f7682

File tree

5 files changed

+71
-361
lines changed

5 files changed

+71
-361
lines changed

src/fuzz_introspector/frontends/frontend_go.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ def has_function_definition(self, target_function_name: str) -> bool:
158158

159159
return False
160160

161-
def get_entry_function_name(self) -> Optional[str]:
161+
def get_entry_function_name(self) -> str:
162162
"""Returns the entry function name of the harness if found,"""
163163
for func in (self.functions + self.methods):
164164
if func.get_name().startswith('Fuzz'):
165165
return func.get_name()
166166

167-
return None
167+
return ''
168168

169169

170170
class Project():

src/fuzz_introspector/frontends/oss_fuzz.py

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,16 @@ def parse_args():
5050
parser.add_argument('--language',
5151
help='Language of target project',
5252
required=True)
53+
5354
return parser.parse_args()
5455

5556

56-
def process_c_project(target_dir, entrypoint, out, module_only=False):
57+
def process_c_project(target_dir: str,
58+
entrypoint: str,
59+
out: str,
60+
module_only: bool = False) -> list[str]:
5761
"""Process a project in C language"""
62+
calltrees = []
5863
source_files = {}
5964
source_files['c'] = frontend_c.capture_source_files_in_tree(
6065
target_dir, 'c')
@@ -99,18 +104,23 @@ def process_c_project(target_dir, entrypoint, out, module_only=False):
99104

100105
logger.info('Extracting calltree for %s', harness.source_file)
101106
calltree = project.extract_calltree(harness, entrypoint)
107+
calltrees.append(calltree)
102108
with open(os.path.join(out, 'fuzzerLogFile-%d.data' % (idx)),
103109
'w',
104110
encoding='utf-8') as f:
105111
f.write("Call tree\n")
106112
f.write(calltree)
107113
f.write("====================================")
108114

115+
return calltrees
116+
109117

110-
def process_cpp_project(target_dir, entrypoint, out):
118+
def process_cpp_project(target_dir: str, entrypoint: str,
119+
out: str) -> list[str]:
111120
"""Process a project in CPP language"""
112121
# Extract c++ source files
113122
logger.info('Going C++ route')
123+
calltrees = []
114124
source_files = []
115125
source_files = frontend_cpp.capture_source_files_in_tree(target_dir)
116126

@@ -136,15 +146,19 @@ def process_cpp_project(target_dir, entrypoint, out):
136146
logger.info(f'Extracting calltree for {harness_name}')
137147
calltree = project.extract_calltree(harness.source_file, harness,
138148
entrypoint)
149+
calltrees.append(calltree)
139150
target = os.path.join(out, f'fuzzerLogFile-{harness_name}.data')
140151
with open(target, 'w', encoding='utf-8') as f:
141152
f.write(f'Call tree\n{calltree}')
142153

154+
return calltrees
155+
143156

144-
def process_go_project(target_dir, out):
157+
def process_go_project(target_dir: str, out: str) -> list[str]:
145158
"""Process a project in Go language"""
146159
# Extract go source files
147160
logger.info('Going Go route')
161+
calltrees = []
148162
source_files = []
149163
source_files = frontend_go.capture_source_files_in_tree(target_dir)
150164

@@ -167,15 +181,20 @@ def process_go_project(target_dir, out):
167181

168182
logger.info(f'Extracting calltree for {harness_name}')
169183
calltree = project.extract_calltree(harness.source_file, harness)
184+
calltrees.append(calltree)
170185
target = os.path.join(out, f'fuzzerLogFile-{harness_name}.data')
171186
with open(target, 'w', encoding='utf-8') as f:
172187
f.write(f'Call tree\n{calltree}')
173188

189+
return calltrees
174190

175-
def process_jvm_project(target_dir, entrypoint, out):
191+
192+
def process_jvm_project(target_dir: str, entrypoint: str,
193+
out: str) -> list[str]:
176194
"""Process a project in JVM based language"""
177195
# Extract java source files
178196
logger.info('Going JVM route')
197+
calltrees = []
179198
source_files = []
180199
source_files = frontend_jvm.capture_source_files_in_tree(target_dir)
181200

@@ -200,15 +219,19 @@ def process_jvm_project(target_dir, entrypoint, out):
200219
# Calltree
201220
logger.info(f'Extracting calltree for {harness_name}')
202221
calltree = project.extract_calltree(harness.source_file, harness)
222+
calltrees.append(calltree)
203223
target = os.path.join(out, f'fuzzerLogFile-{harness_name}.data')
204224
with open(target, 'w', encoding='utf-8') as f:
205225
f.write(f'Call tree\n{calltree}')
206226

227+
return calltrees
228+
207229

208-
def process_rust_project(target_dir, out):
230+
def process_rust_project(target_dir: str, out: str) -> list[str]:
209231
"""Process a project in Rust based language"""
210232
# Extract rust source files
211233
logger.info('Going Rust route')
234+
calltrees = []
212235
source_files = []
213236
source_files = frontend_rust.capture_source_files_in_tree(target_dir)
214237

@@ -233,28 +256,33 @@ def process_rust_project(target_dir, out):
233256
# Calltree
234257
logger.info(f'Extracting calltree for {harness_name}')
235258
calltree = project.extract_calltree(harness.source_file, harness)
259+
calltrees.append(calltree)
236260
target = os.path.join(out, f'fuzzerLogFile-{harness_name}.data')
237261
with open(target, 'w', encoding='utf-8') as f:
238262
f.write(f'Call tree\n{calltree}')
239263

264+
return calltrees
265+
240266

241267
def analyse_folder(language: str = '',
242268
directory: str = '',
243269
entrypoint: str = '',
244270
out='',
245-
module_only=False):
271+
module_only=False) -> list[str]:
246272
"""Runs a full frontend analysis on a given directory"""
247273

248274
if language == 'c':
249-
process_c_project(directory, entrypoint, out, module_only)
250-
if language.lower() in ['cpp', 'c++']:
251-
process_cpp_project(directory, entrypoint, out)
252-
if language == 'go':
253-
process_go_project(directory, out)
254-
if language == 'jvm':
255-
process_jvm_project(directory, entrypoint, out)
256-
if language == 'rust':
257-
process_rust_project(directory, out)
275+
return process_c_project(directory, entrypoint, out, module_only)
276+
elif language.lower() in ['cpp', 'c++']:
277+
return process_cpp_project(directory, entrypoint, out)
278+
elif language == 'go':
279+
return process_go_project(directory, out)
280+
elif language == 'jvm':
281+
return process_jvm_project(directory, entrypoint, out)
282+
elif language == 'rust':
283+
return process_rust_project(directory, out)
284+
285+
return []
258286

259287

260288
def main():

tests/tree-sitter-frontend/cpp/test-project-1/fuzzerLogFile-sample.data

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)