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

[helper] Run with .options. #65

Closed
wants to merge 1 commit into from
Closed
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
35 changes: 31 additions & 4 deletions infra/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from __future__ import print_function
import argparse
from ConfigParser import ConfigParser
import os
import pipes
import re
Expand All @@ -29,6 +30,7 @@

OSSFUZZ_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
BUILD_DIR = os.path.join(OSSFUZZ_DIR, 'build')
TARGETS_DIR = os.path.join(OSSFUZZ_DIR, 'targets')


def main():
Expand Down Expand Up @@ -93,6 +95,29 @@ def _get_version_control_url(target_name):
return None, None


def _get_fuzzer_options(target_name, fuzzer_name):
"""Get fuzzer options if exists."""
fuzzer_directory = os.path.join(TARGETS_DIR, target_name)
options_file_path = os.path.join(fuzzer_directory, fuzzer_name + '.options')
if not os.path.isfile(options_file_path):
return []

config = ConfigParser()
config.read(options_file_path)

if not config.has_section('libfuzzer'):
return []

options = []
for key, value in config.items('libfuzzer'):
if key == 'dict':
value = os.path.join('/out', value)

options.append('-%s=%s' % (key, value))

return options


def build_image(build_args):
"""Build docker image."""
parser = argparse.ArgumentParser('helper.py build_image')
Expand All @@ -104,7 +129,7 @@ def build_image(build_args):

command = [
'docker', 'build', '--pull', '-t', 'ossfuzz/' + args.target_name,
os.path.join("targets", args.target_name)
os.path.join('targets', args.target_name)
]
print('Running:', _get_command_string(command))

Expand Down Expand Up @@ -162,17 +187,19 @@ def run_fuzzer(run_args):
file=sys.stderr)
return 1

fuzzer_options = _get_fuzzer_options(args.target_name, args.fuzzer_name)
command = [
'docker', 'run', '-i',
'-v', '%s:/out' % os.path.join(BUILD_DIR, 'out'),
'-v', '%s:/out' % os.path.join(BUILD_DIR, 'out', args.target_name),
'-t', 'ossfuzz/libfuzzer-runner',
'/out/%s/%s' %(args.target_name, args.fuzzer_name)
] + args.fuzzer_args
'/out/%s' % args.fuzzer_name
] + args.fuzzer_args + fuzzer_options

print('Running:', _get_command_string(command))
pipe = subprocess.Popen(command)
pipe.communicate()


def coverage(run_args):
"""Runs a fuzzer in the container."""
parser = argparse.ArgumentParser('helper.py coverage')
Expand Down