helper.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/python
  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. """Fuzzing helper, creates and uses corpus/crash directories.
  10. fuzzer.py <fuzzer> <extra fuzzer arguments>
  11. """
  12. import os
  13. import subprocess
  14. import sys
  15. FUZZER = sys.argv[1]
  16. THIS_DIR = os.path.abspath(os.path.dirname(__file__))
  17. CORPORA_DIR = os.path.abspath(os.path.join(THIS_DIR, "corpora"))
  18. FUZZER_DIR = os.path.abspath(os.path.join(CORPORA_DIR, FUZZER))
  19. if not os.path.isdir(FUZZER_DIR):
  20. os.mkdir(FUZZER_DIR)
  21. corpora = []
  22. def _create(d):
  23. dd = os.path.abspath(os.path.join(CORPORA_DIR, d))
  24. if not os.path.isdir(dd):
  25. os.mkdir(dd)
  26. corpora.append(dd)
  27. def _add(d):
  28. dd = os.path.abspath(os.path.join(CORPORA_DIR, d))
  29. if os.path.isdir(dd):
  30. corpora.append(dd)
  31. def main():
  32. _create(FUZZER)
  33. _create(FUZZER + "-crash")
  34. _add(FUZZER + "-seed")
  35. cmd = ([os.path.abspath(os.path.join(THIS_DIR, FUZZER))] + sys.argv[2:]
  36. + ["-artifact_prefix=" + corpora[1] + "/"] + corpora)
  37. print(" ".join(cmd))
  38. subprocess.call(cmd)
  39. if __name__ == "__main__":
  40. main()