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

webapp: provide initial sample of using type map #1468

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions tools/web-fuzzing-introspection/app/static/assets/db/oss_fuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def get_introspector_report_url_base(project_name, datestr):
project_url = base_url.format(project_name, datestr)
return project_url

def get_introspector_type_map_url_summary(project_name, datestr):
return get_introspector_report_url_base(project_name,
datestr) + "all-friendly-debug-types.json"

def get_introspector_report_url_summary(project_name, datestr):
return get_introspector_report_url_base(project_name,
Expand Down Expand Up @@ -124,6 +127,24 @@ def extract_introspector_report(project_name, date_str):
return introspector_report


def get_introspector_type_map(project_name, date_str):
introspector_type_api_url = get_introspector_type_map_url_summary(
project_name, date_str.replace("-", ""))

# Read the introspector atifact
try:
raw_introspector_json_request = requests.get(introspector_type_api_url,
timeout=10)
except:
return None
try:
introspector_type_map = json.loads(raw_introspector_json_request.text)
except:
return None

return introspector_type_map


def get_projects_build_status():
fuzz_build_url = constants.OSS_FUZZ_BUILD_STATUS_URL + '/' + constants.FUZZ_BUILD_JSON
coverage_build_url = constants.OSS_FUZZ_BUILD_STATUS_URL + '/' + constants.COVERAGE_BUILD_JSON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ def save_debug_report(debug_report, project_name):
json.dump(debug_report, report_fd)


def save_type_map(debug_report, project_name):
project_db_dir = os.path.join(constants.DB_PROJECT_DIR, project_name)
os.makedirs(project_db_dir, exist_ok=True)

report_dst = os.path.join(project_db_dir, 'type_map.json')
with open(report_dst, 'w') as report_fd:
json.dump(debug_report, report_fd)


def save_branch_blockers(branch_blockers, project_name):
project_db_dir = os.path.join(constants.DB_PROJECT_DIR, project_name)
os.makedirs(project_db_dir, exist_ok=True)
Expand Down Expand Up @@ -297,6 +306,14 @@ def extract_project_data(project_name, date_str, should_include_details,
project_name, date_str)
introspector_report_url = oss_fuzz.get_introspector_report_url_report(
project_name, date_str.replace("-", ""))
introspector_type_map = oss_fuzz.get_introspector_type_map(
project_name, date_str.replace("-", ""))

#print("Type mapping:")
if introspector_type_map:
save_type_map(introspector_type_map, project_name)
# for addr in introspector_type_map:
# print("Addr: %s"%(str(addr)))

# Save the report
save_fuzz_introspector_report(introspector_report, project_name, date_str)
Expand Down Expand Up @@ -825,7 +842,7 @@ def get_dates_to_analyse(since_date, days_to_analyse, day_offset):
delta = today - start_date
days_to_analyse = delta.days - 1
day_offset = 0
date_range = create_date_range(day_offset, days_to_analyse)
date_range = create_date_range(-1, days_to_analyse)

return date_range

Expand Down Expand Up @@ -892,7 +909,7 @@ def get_cmdline_parser():
parser.add_argument("--base-offset",
help="Day offset",
type=int,
default=1)
default=0)
parser.add_argument(
"--since-date",
help="Include data from this date an onwards, in format \"d-m-y\"",
Expand Down
36 changes: 36 additions & 0 deletions tools/web-fuzzing-introspection/app/webapp/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import random
import requests
import json
Expand Down Expand Up @@ -990,6 +991,41 @@ def get_build_status_of_project(project_name):

return None

@blueprint.route('/api/type-at-addr')
def type_at_addr():
project = request.args.get('project', None)
if project == None:
return {
'result': 'error',
'extended_msgs': ['Please provide project name']
}

addr = request.args.get('addr', None)
if addr == None:
return {
'result': 'error',
'extended_msgs': ['Please provide project name']
}

print("Opening type map")
type_map = os.path.join(
os.path.dirname(__file__),
f"../static/assets/db/db-projects/{project}/type_map.json")

with open(type_map, 'r') as f:
type_map_dict = json.load(f)

print("Tring to find: [%s]"%(addr))
if addr in type_map_dict:
return {
'result': 'success',
'data': type_map_dict[addr]
}
for k in type_map:
print(k)
return {'result': 'error'}



@blueprint.route('/api/far-reach-but-low-coverage')
def far_reach_but_low_coverage():
Expand Down
Loading