Skip to content

Commit

Permalink
webapi: add optimal target analysis API (#1642)
Browse files Browse the repository at this point in the history
* webapp: apis: enable sorting out non-declared functins

Signed-off-by: David Korczynski <[email protected]>

* webapp: add optimal target analysis API

Ref:
google/oss-fuzz-gen#356 (comment)

Signed-off-by: David Korczynski <[email protected]>

---------

Signed-off-by: David Korczynski <[email protected]>
  • Loading branch information
Arifdev1 committed Jul 2, 2024
1 parent ae12e84 commit 263344e
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,9 @@ def extract_project_data(project_name, date_str, should_include_details,
functions_covered_estimate = project_stats[
'code-coverage-function-percentage']

optimal_targets = introspector_report.get('analyses', {}).get(
'OptimalTargets', [])

# Get details if needed and otherwise leave empty
refined_proj_list = list()
refined_constructor_list = list()
Expand Down Expand Up @@ -581,6 +584,7 @@ def extract_project_data(project_name, date_str, should_include_details,
'refined_proj_list': refined_proj_list,
'refined_constructor_list': refined_constructor_list,
'annotated_cfg': annotated_cfg,
'optimal_targets': optimal_targets,
}

code_coverage_data_dict = extract_code_coverage_data(
Expand Down
71 changes: 71 additions & 0 deletions tools/web-fuzzing-introspection/app/webapp/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,77 @@ def api():
return render_template('api.html', gtag=gtag)


@blueprint.route('/api/optimal-targets')
def api_optimal_targets():
"""Returns the list of functions generated by Fuzz Introspector's analysis
`Optimal Targets`.
"""
project_name = request.args.get('project', None)
if project_name is None:
return {'result': 'error', 'msg': 'Please provide project name'}

target_project = None
all_projects = data_storage.get_projects()
for project in all_projects:
if project.name == project_name:
target_project = project
break
if target_project is None:
return {'result': 'error', 'msg': 'Project not in the database'}

if target_project.introspector_data is None:
return {'result': 'error', 'msg': 'Found no introspector data.'}

all_functions = data_storage.get_functions()
project_functions = []
for function in all_functions:
if function.project == project_name:
project_functions.append(function)

try:
optimal_targets_raw = target_project.introspector_data[
'optimal_targets']
function_model_optimal_targets = []
for function in optimal_targets_raw:
substituted_function = None
for model_func in project_functions:
if model_func.name == function['name'].replace(' ', ''):
substituted_function = {
'function_name': model_func.name,
'function_filename': model_func.function_filename,
'runtime_coverage_percent':
model_func.runtime_code_coverage,
'accummulated_complexity':
model_func.accummulated_cyclomatic_complexity,
'function_arguments': model_func.function_arguments,
'function_argument_names':
model_func.function_argument_names,
'return_type': model_func.return_type,
'is_reached': model_func.is_reached,
'reached_by_fuzzers': model_func.reached_by_fuzzers,
'raw_function_name': model_func.raw_function_name,
'source_line_begin': model_func.source_line_begin,
'source_line_end': model_func.source_line_end,
'function_signature': model_func.func_signature,
'debug_summary': model_func.debug_data,
}
break
if substituted_function:
function_model_optimal_targets.append(substituted_function)

return {
'result': 'success',
'project': {
'name': project_name,
'functions': function_model_optimal_targets
}
}
except KeyError:
return {'result': 'error', 'msg': 'Found no optimal analysis.'}
except TypeError:
return {'result': 'error', 'msg': 'Found no introspector data.'}


@blueprint.route('/api/annotated-cfg')
def api_annotated_cfg():
project_name = request.args.get('project', None)
Expand Down

0 comments on commit 263344e

Please sign in to comment.