fuzzyinput.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import sys
00004 import os
00005 import subprocess
00006 
00007 iterations = 100    # by default
00008 fuzzy_ratio = 0.01
00009 
00010 # When executed from the command line
00011 if __name__ == "__main__":
00012     # Input arguments
00013     asebatest_bin = None
00014     input_script = None
00015     if len(sys.argv) in [3, 4]:
00016         asebatest_bin = sys.argv[1]
00017         input_script = sys.argv[2]
00018         if len(sys.argv) == 4:
00019             iterations = int(sys.argv[3])
00020     else:
00021         print >> sys.stderr, "Wrong number of arguments.\n"
00022         print >> sys.stderr, "Usage:"
00023         print >> sys.stderr, "  {} asebatest_bin input_script".format(sys.argv[0])
00024         exit(1)
00025 
00026 try:
00027     f = open(input_script, 'rb')
00028 except IOError, e:
00029     print "Can not find the script file {}. Error.".format(input_script)
00030     exit(2)
00031 
00032 # read the script
00033 script = f.read()
00034 f.close()
00035 
00036 # run several fuzzing loops, changing the seed at each step
00037 failed = False
00038 for s in range(0,iterations):
00039     #subprocess.call(["zzuf", "-P", r"\n", "-R", r"\x00-\x1f\x7f-\xff", "-r{}".format(fuzzy_ratio), "-s", str(s), "cat", input_script])
00040     retcode = subprocess.call(["zzuf", "-P", r"\n", "-R", r"\x00-\x1f\x7f-\xff", "-r".format(fuzzy_ratio), "-s", str(s), asebatest_bin, input_script], \
00041             stdout=open(os.devnull), stderr=open(os.devnull))
00042     if retcode == 1:
00043         # oops, the child of zzuf crashed (sigsev?)
00044         print >> sys.stderr, "Compiler crached when fuzzing the input script."
00045         print >> sys.stderr, "Faulty script is generated with the seed (-s) {}:".format(s)
00046         subprocess.call(["zzuf", "-P", r"\n", "-R", r"\x00-\x1f\x7f-\xff", "-r{}".format(fuzzy_ratio), "-s", str(s), "cat", input_script])
00047         failed = True
00048         break
00049 
00050 if failed == True:
00051     exit(3)
00052 else:
00053     exit(0)
00054 


aseba
Author(s): Stéphane Magnenat
autogenerated on Sun Oct 5 2014 23:46:38