Lines Matching +full:oss +full:- +full:fuzz +full:- +full:project +full:- +full:name
8 # http://www.apache.org/licenses/LICENSE-2.0
17 """Helper script for OSS-Fuzz users. Can do common tasks like building
36 'gcr.io/oss-fuzz-base/base-image',
37 'gcr.io/oss-fuzz-base/base-clang',
38 'gcr.io/oss-fuzz-base/base-builder',
39 'gcr.io/oss-fuzz-base/base-runner',
40 'gcr.io/oss-fuzz-base/base-runner-debug',
41 'gcr.io/oss-fuzz-base/base-sanitizer-libs-builder',
42 'gcr.io/oss-fuzz-base/msan-libs-builder',
45 VALID_PROJECT_NAME_REGEX = re.compile(r'^[a-zA-Z0-9_-]+$')
49 raw_input = input # pylint: disable=invalid-name
52 'gs://{project_name}-corpus.clusterfuzz-external.appspot.com/libFuzzer/'
55 'gs://{project_name}-backup.clusterfuzz-external.appspot.com/corpus/'
60 # Languages from project.yaml that have code coverage support.
63 # pylint: disable=too-many-lines
66 def main(): # pylint: disable=too-many-branches,too-many-return-statements
114 def get_parser(): # pylint: disable=too-many-statements
116 parser = argparse.ArgumentParser('helper.py', description='oss-fuzz helpers')
120 'generate', help='Generate files for new project.')
126 build_image_parser.add_argument('--pull',
129 build_image_parser.add_argument('--no-pull',
134 'build_fuzzers', help='Build fuzzers for a project.')
143 build_fuzzers_parser.add_argument('--clean',
147 build_fuzzers_parser.add_argument('--no-clean',
164 check_build_parser.add_argument('project_name', help='name of the project')
166 help='name of the fuzzer',
175 '--corpus-dir', help='directory to store corpus for the fuzz target')
176 run_fuzzer_parser.add_argument('project_name', help='name of the project')
177 run_fuzzer_parser.add_argument('fuzzer_name', help='name of the fuzzer')
183 'coverage', help='Generate code coverage report for the project.')
184 coverage_parser.add_argument('--no-corpus-download',
187 'OSS-Fuzz; use corpus located in '
188 'build/corpus/<project>/<fuzz_target>/')
189 coverage_parser.add_argument('--port',
193 coverage_parser.add_argument('--fuzz-target',
194 help='specify name of a fuzz '
197 coverage_parser.add_argument('--corpus-dir',
199 ' to be used (requires --fuzz-target argument)')
200 coverage_parser.add_argument('project_name', help='name of the project')
203 'pass to llvm-cov utility.',
207 'download_corpora', help='Download all corpora for a project.')
208 download_corpora_parser.add_argument('--fuzz-target',
209 help='specify name of a fuzz target')
211 help='name of the project')
215 reproduce_parser.add_argument('--valgrind',
218 reproduce_parser.add_argument('project_name', help='name of the project')
219 reproduce_parser.add_argument('fuzzer_name', help='name of the fuzzer')
228 shell_parser.add_argument('project_name', help='name of the project')
242 """Checks if the image name is a base image."""
243 return os.path.exists(os.path.join('infra', 'base-images', image_name))
247 """Checks if a project exists."""
257 command = ['docker', 'run', '--rm']
258 command.extend(['-v', '%s:/out' % _get_output_dir(project_name)])
261 command.extend(['/bin/bash', '-c', 'test -f /out/%s' % fuzzer_name])
285 """Returns path to the project."""
290 """Returns path to the project Dockerfile."""
295 """Creates and returns path to /corpus directory for the given project (if
305 """Creates and returns path to /out directory for the given project (if
315 """Creates and returns path to /work directory for the given project (if
325 """Returns project language."""
327 'project.yaml')
340 parser.add_argument('--architecture', default='x86_64', choices=choices)
347 parser.add_argument('--engine', default='libfuzzer', choices=choices)
355 '--sanitizer',
363 parser.add_argument('-e',
373 image_project = 'oss-fuzz-base'
374 dockerfile_dir = os.path.join('infra', 'base-images', image_name)
376 image_project = 'oss-fuzz'
384 build_args.append('--no-cache')
387 '-t', 'gcr.io/%s/%s' % (image_project, image_name), dockerfile_dir
395 return sum([['-e', v] for v in env_list], [])
418 """Parse WORKDIR from the Dockerfile for the given project."""
429 command = ['docker', 'run', '--rm', '--privileged']
433 command.append('-i')
454 command.append('--pull')
485 print('Incompatible arguments --pull and --no-pull.')
508 def build_fuzzers_impl( # pylint: disable=too-many-arguments,too-many-locals,too-many-branches
526 print('WARNING: language not specified in project.yaml. Build may fail.')
531 # Clean old and possibly conflicting artifacts in project's out directory.
533 '-v',
534 '%s:/out' % project_out_dir, '-t',
535 'gcr.io/oss-fuzz/%s' % project_name, '/bin/bash', '-c', 'rm -rf /out/*'
539 '-v',
540 '%s:/work' % project_work_dir, '-t',
541 'gcr.io/oss-fuzz/%s' % project_name, '/bin/bash', '-c', 'rm -rf /work/*'
545 print('Keeping existing build artifacts as-is (if any).')
561 '-v',
562 '%s:/work' % project_work_dir, 'gcr.io/oss-fuzz-base/msan-libs-builder',
563 'bash', '-c', 'cp -r /msan /work'
567 command = ['--cap-add', 'SYS_PTRACE'] + _env_to_docker_args(env)
572 '-v',
582 '-v',
587 '-v',
588 '%s:/out' % project_out_dir, '-v',
589 '%s:/work' % project_work_dir, '-t',
590 'gcr.io/oss-fuzz/%s' % project_name
601 '-v',
602 '%s:/out' % project_out_dir, '-v',
605 'gcr.io/oss-fuzz-base/base-sanitizer-libs-builder', 'patch_build.py',
630 print('WARNING: language not specified in project.yaml. Defaulting to C++.')
643 '-v',
644 '%s:/out' % _get_output_dir(args.project_name), '-t',
645 'gcr.io/oss-fuzz-base/base-runner'
663 """Return names of fuzz targest build in the project's /out directory."""
665 for name in os.listdir(_get_output_dir(project_name)):
666 if name.startswith('afl-'):
669 path = os.path.join(_get_output_dir(project_name), name)
671 fuzz_targets.append(name)
677 """Download the latest corpus for the given fuzz target."""
690 # asking for two-factor authentication.
694 # Some fuzz targets (e.g. new ones) may not have corpus yet, just skip those.
701 latest_backup_url = output.splitlines()[-1]
703 command = ['gsutil', '-q', 'cp', latest_backup_url, archive_path]
706 command = ['unzip', '-q', '-o', archive_path, '-d', corpus_dir]
713 command = ['gsutil', '-m', '-q', 'rsync', '-R', corpus_url, corpus_dir]
718 """Download most recent corpora from GCS for the given project."""
724 subprocess.check_call(['gsutil', '--version'], stdout=stdout)
745 except Exception as error: # pylint:disable=broad-except
751 print('Downloading corpora for %s project to %s' %
761 'ERROR: --corpus-dir requires specifying a particular fuzz target '
762 'using --fuzz-target',
772 'ERROR: Project is written in %s, coverage for it is not supported yet.'
784 'PROJECT=%s' % args.project_name,
794 '-p',
800 print('ERROR: the path provided in --corpus-dir argument does not exist',
804 run_args.extend(['-v', '%s:/corpus/%s' % (corpus_dir, args.fuzz_target)])
806 run_args.extend(['-v', '%s:/corpus' % _get_corpus_dir(args.project_name)])
809 '-v',
811 '-t',
812 'gcr.io/oss-fuzz-base/base-runner',
849 print('ERROR: the path provided in --corpus-dir argument does not exist',
854 '-v',
860 '-v',
862 '-t',
863 'gcr.io/oss-fuzz-base/base-runner',
872 """Reproduce a specific test case from a specific project."""
877 def reproduce_impl( # pylint: disable=too-many-arguments
895 image_name = 'base-runner'
898 debugger = 'valgrind --tool=memcheck --track-origins=yes --leak-check=full'
901 image_name = 'base-runner-debug'
908 '-v',
910 '-v',
912 '-t',
913 'gcr.io/oss-fuzz-base/%s' % image_name,
916 '-runs=100',
923 """Generate empty project files."""
925 print('Project name needs to be less than or equal to %d characters.' %
931 print('Invalid project name.', file=sys.stderr)
950 with open(os.path.join(directory, 'project.yaml'), 'w') as file_handle:
975 if args.project_name != 'base-runner-debug':
982 image_project = 'oss-fuzz-base'
985 image_project = 'oss-fuzz'
991 '-v',
996 '-v',
997 '%s:/out' % out_dir, '-v',
998 '%s:/work' % _get_work_dir(args.project_name), '-t',