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