1 #!/usr/bin/python 2 # 3 # Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved. 4 # 5 # Licensed under the OpenSSL license (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 12 fuzzer.py <fuzzer> <extra fuzzer arguments> 13 """ 14 15 import os 16 import subprocess 17 import sys 18 19 FUZZER = sys.argv[1] 20 21 THIS_DIR = os.path.abspath(os.path.dirname(__file__)) 22 CORPORA_DIR = os.path.abspath(os.path.join(THIS_DIR, "corpora")) 23 24 FUZZER_DIR = os.path.abspath(os.path.join(CORPORA_DIR, FUZZER)) 25 if not os.path.isdir(FUZZER_DIR): 26 os.mkdir(FUZZER_DIR) 27 28 corpora = [] 29 30 def _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 36 def _add(d): 37 dd = os.path.abspath(os.path.join(CORPORA_DIR, d)) 38 if os.path.isdir(dd): 39 corpora.append(dd) 40 41 def 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 51 if __name__ == "__main__": 52 main() 53