1#!/usr/bin/env python3 2# 3# Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. 4# 5# Licensed under the Apache License 2.0 (the "License"). You may not use 6# this file except in compliance with the License. You can obtain a copy 7# in the file LICENSE in the source distribution or at 8# https://www.openssl.org/source/license.html 9 10"""Fuzzing helper, creates and uses corpus/crash directories. 11 12fuzzer.py <fuzzer> <extra fuzzer arguments> 13""" 14 15import os 16import subprocess 17import sys 18 19FUZZER = sys.argv[1] 20 21THIS_DIR = os.path.abspath(os.path.dirname(__file__)) 22CORPORA_DIR = os.path.abspath(os.path.join(THIS_DIR, "corpora")) 23 24FUZZER_DIR = os.path.abspath(os.path.join(CORPORA_DIR, FUZZER)) 25if not os.path.isdir(FUZZER_DIR): 26 os.mkdir(FUZZER_DIR) 27 28corpora = [] 29 30def _create(d): 31 dd = os.path.abspath(os.path.join(CORPORA_DIR, d)) 32 if not os.path.isdir(dd): 33 os.mkdir(dd) 34 corpora.append(dd) 35 36def _add(d): 37 dd = os.path.abspath(os.path.join(CORPORA_DIR, d)) 38 if os.path.isdir(dd): 39 corpora.append(dd) 40 41def main(): 42 _create(FUZZER) 43 _create(FUZZER + "-crash") 44 _add(FUZZER + "-seed") 45 46 cmd = ([os.path.abspath(os.path.join(THIS_DIR, FUZZER))] + sys.argv[2:] 47 + ["-artifact_prefix=" + corpora[1] + "/"] + corpora) 48 print(" ".join(cmd)) 49 subprocess.call(cmd) 50 51if __name__ == "__main__": 52 main() 53