Skip to content

Commit 2c303e6

Browse files
webapp: add API to get all header files of project (#1552)
* webapp: check for constructor file Signed-off-by: David Korczynski <david@adalogics.com> * webapp: add API to get all header files of project Signed-off-by: David Korczynski <david@adalogics.com> --------- Signed-off-by: David Korczynski <david@adalogics.com>
1 parent cba4f21 commit 2c303e6

File tree

4 files changed

+98
-7
lines changed

4 files changed

+98
-7
lines changed

tools/web-fuzzing-introspection/app/static/assets/db/web_db_creator_from_summary.py

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,27 @@ def extract_local_project_data(project_name, oss_fuzz_path,
289289
debug_report = oss_fuzz.extract_local_introspector_debug_info(
290290
project_name, oss_fuzz_path)
291291

292+
if debug_report:
293+
all_files_in_project = debug_report.get('all_files_in_project', [])
294+
all_header_files_in_project = set()
295+
for elem in all_files_in_project:
296+
source_file = elem.get('source_file', '')
297+
if source_file.endswith('.h'):
298+
normalized_file = os.path.normpath(source_file)
299+
if '/usr/local/' in normalized_file or '/usr/include/' in normalized_file:
300+
continue
301+
all_header_files_in_project.add(normalized_file)
302+
303+
all_header_files = {
304+
'project': project_name.split('###')[0],
305+
'all-header-files': list(all_header_files_in_project)
306+
}
307+
else:
308+
all_header_files = {
309+
'project': project_name.split('###')[0],
310+
'all-header-files': list()
311+
}
312+
292313
# Refine the data
293314
all_function_list = oss_fuzz.extract_local_introspector_function_list(
294315
project_name, oss_fuzz_path)
@@ -351,6 +372,7 @@ def extract_local_project_data(project_name, oss_fuzz_path,
351372
'project_timestamp': project_timestamp,
352373
"introspector-data-dict": introspector_data_dict,
353374
"coverage-data-dict": code_coverage_data_dict,
375+
'all-header-files': all_header_files,
354376
}
355377

356378

@@ -449,6 +471,27 @@ def extract_project_data(project_name, date_str, should_include_details,
449471
else:
450472
debug_report = None
451473

474+
if debug_report:
475+
all_files_in_project = debug_report.get('all_files_in_project', [])
476+
all_header_files_in_project = set()
477+
for elem in all_files_in_project:
478+
source_file = elem.get('source_file', '')
479+
if source_file.endswith('.h'):
480+
normalized_file = os.path.normpath(source_file)
481+
if '/usr/local/' in normalized_file or '/usr/include/' in normalized_file:
482+
continue
483+
all_header_files_in_project.add(normalized_file)
484+
485+
all_header_files = {
486+
'project': project_name.split('###')[0],
487+
'all-header-files': list(all_header_files_in_project)
488+
}
489+
else:
490+
all_header_files = {
491+
'project': project_name.split('###')[0],
492+
'all-header-files': list()
493+
}
494+
452495
# Currently, we fail if any of code_coverage_summary of introspector_report is
453496
# None. This should later be adjusted such that we can continue if we only
454497
# have code coverage but no introspector data. However, we need to adjust
@@ -551,6 +594,7 @@ def extract_project_data(project_name, date_str, should_include_details,
551594
'project_timestamp': project_timestamp,
552595
"introspector-data-dict": introspector_data_dict,
553596
"coverage-data-dict": code_coverage_data_dict,
597+
'all-header-files': all_header_files,
554598
}
555599
return
556600

@@ -571,6 +615,7 @@ def analyse_list_of_projects(date, projects_to_analyse,
571615
function_list = list()
572616
constructor_list = list()
573617
project_timestamps = list()
618+
all_header_files = list()
574619
accummulated_fuzzer_count = 0
575620
accummulated_function_count = 0
576621
accummulated_covered_functions = 0
@@ -645,6 +690,9 @@ def analyse_list_of_projects(date, projects_to_analyse,
645690
'function_coverage_estimate'] += introspector_dictionary[
646691
'functions_covered_estimate']
647692

693+
all_header_files.append(
694+
analyses_dictionary[project_key]['all-header-files'])
695+
648696
coverage_dictionary = analyses_dictionary[project_key].get(
649697
'coverage-data-dict', None)
650698
if coverage_dictionary != None:
@@ -662,7 +710,7 @@ def analyse_list_of_projects(date, projects_to_analyse,
662710
# - all constructors (maybe empty)
663711
# - a list of project timestamps
664712
# - the DB timestamp
665-
return function_list, constructor_list, project_timestamps, db_timestamp
713+
return function_list, constructor_list, project_timestamps, db_timestamp, all_header_files
666714

667715

668716
def extend_db_timestamps(db_timestamp, output_directory):
@@ -752,9 +800,13 @@ def extend_func_db(function_list, output_directory, target):
752800
json.dump(all_functions, f)
753801

754802

755-
def update_db_files(db_timestamp, project_timestamps, function_list,
756-
constructor_list, output_directory,
757-
should_include_details):
803+
def update_db_files(db_timestamp,
804+
project_timestamps,
805+
function_list,
806+
constructor_list,
807+
output_directory,
808+
should_include_details,
809+
all_header_files=dict()):
758810
logger.info(
759811
"Updating the database with DB snapshot. Number of functions in total: %d"
760812
% (db_timestamp['function_count']))
@@ -763,6 +815,9 @@ def update_db_files(db_timestamp, project_timestamps, function_list,
763815
extend_func_db(constructor_list, output_directory,
764816
DB_JSON_ALL_CONSTRUCTORS)
765817

818+
with open('all-header-files.json', 'w') as f:
819+
f.write(json.dumps(all_header_files))
820+
766821
extend_db_json_files(project_timestamps, output_directory)
767822
extend_db_timestamps(db_timestamp, output_directory)
768823

@@ -840,14 +895,15 @@ def analyse_set_of_dates(dates, projects_to_analyse, output_directory,
840895
if force_creation:
841896
is_end = True
842897

843-
function_list, constructor_list, project_timestamps, db_timestamp = analyse_list_of_projects(
898+
function_list, constructor_list, project_timestamps, db_timestamp, all_header_files = analyse_list_of_projects(
844899
date, projects_to_analyse, should_include_details=is_end)
845900
update_db_files(db_timestamp,
846901
project_timestamps,
847902
function_list,
848903
constructor_list,
849904
output_directory,
850-
should_include_details=is_end)
905+
should_include_details=is_end,
906+
all_header_files=all_header_files)
851907

852908

853909
def get_date_at_offset_as_str(day_offset=-1):
@@ -1074,13 +1130,18 @@ def create_local_db(oss_fuzz_path):
10741130
extract_local_project_data(project, oss_fuzz_path, analyses_dictionary)
10751131

10761132
# Accummulate the data from all the projects.
1133+
all_header_files = []
10771134
for project_key in analyses_dictionary:
10781135
# Append project timestamp to the list of timestamps
10791136
project_timestamp = analyses_dictionary[project_key][
10801137
'project_timestamp']
10811138
project_timestamps.append(project_timestamp)
10821139
db_timestamp['fuzzer_count'] += project_timestamp['fuzzer-count']
10831140

1141+
# Extend all header files
1142+
all_header_files.append(
1143+
analyses_dictionary[project_key]['all-header-files'])
1144+
10841145
# Accummulate all function list and branch blockers
10851146
introspector_dictionary = project_timestamp.get(
10861147
'introspector-data', None)
@@ -1120,7 +1181,8 @@ def create_local_db(oss_fuzz_path):
11201181
function_list,
11211182
constructor_list,
11221183
os.getcwd(),
1123-
should_include_details=True)
1184+
should_include_details=True,
1185+
all_header_files=all_header_files)
11241186

11251187

11261188
def create_db(max_projects, days_to_analyse, output_directory, input_directory,

tools/web-fuzzing-introspection/app/webapp/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ def load_db():
3232
project_currents = os.path.join(
3333
os.path.dirname(__file__),
3434
"../static/assets/db/all-project-current.json")
35+
3536
projects_build_status = os.path.join(
3637
os.path.dirname(__file__), "../static/assets/db/build-status.json")
38+
all_header_files_file = os.path.join(
39+
os.path.dirname(__file__), "../static/assets/db/all-header-files.json")
3740

3841
if len(data_storage.DB_TIMESTAMPS) > 0:
3942
return
@@ -140,6 +143,11 @@ def load_db():
140143
coverage_build_log=project_dict['cov-build-log'],
141144
fuzz_build_log=project_dict['fuzz-build-log']))
142145

146+
if os.path.isfile(all_header_files_file):
147+
with open(all_header_files_file, 'r') as f:
148+
all_header_files = json.load(f)
149+
data_storage.ALL_HEADER_FILES = all_header_files
150+
143151
return
144152

145153

tools/web-fuzzing-introspection/app/webapp/data_storage.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
PROJECT_DEBUG_DATA = []
2626

27+
ALL_HEADER_FILES = []
28+
2729

2830
def get_projects():
2931
return PROJECTS

tools/web-fuzzing-introspection/app/webapp/routes.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,25 @@ def shutdown():
13511351
return {'result': 'failed', 'msg': 'not a local server'}
13521352

13531353

1354+
@blueprint.route('/api/all-header-files')
1355+
def all_project_header_files():
1356+
project = request.args.get('project', None)
1357+
if project == None:
1358+
return {
1359+
'result': 'error',
1360+
'extended_msgs': ['Please provide project name']
1361+
}
1362+
1363+
for elem in data_storage.ALL_HEADER_FILES:
1364+
if elem['project'] == project:
1365+
return {
1366+
'result': 'success',
1367+
'all-header-files': elem['all-header-files']
1368+
}
1369+
1370+
return {'result': 'failed', 'msg': 'did not find project'}
1371+
1372+
13541373
@blueprint.route('/api/addr-to-recursive-dwarf-info')
13551374
def type_at_addr():
13561375
project = request.args.get('project', None)

0 commit comments

Comments
 (0)