]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
tools/insn-fuzz: Accept fuzzing input on stdin
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 2 Mar 2017 17:24:30 +0000 (17:24 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 20 Mar 2017 16:45:20 +0000 (16:45 +0000)
This is rather faster for afl-fuzz to arrange than using an explicit file
parameter.  Also update the README to recommend using a tmpfs for findings_dir
which reduces disk load and is more performant.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
tools/fuzz/README.afl
tools/fuzz/x86_instruction_emulator/afl-harness.c

index 357c3c8753c7cd7f8834c39178c859563c830546..c5f749a6f87caae12809cc3b2d8786eafb016b04 100644 (file)
@@ -25,8 +25,11 @@ Use the x86 instruction emulator fuzzer as an example.
    $ dd if=/dev/urandom of=testcase_dir/rand.bin \
        bs=`./afl-harness --min-input-size` count=1
 
+3a. use a tmpfs for findings_dir (Perf improvement and reduced disk load)
+   $ mkdir findings_dir
+   $ mount -t tmpfs -o size=512M tmpfs findings_dir
+
 4. run the fuzzer with AFL:
-   $ $AFLPATH/afl-fuzz -m none -t 1000 -i testcase_dir -o findings_dir -- \
-     ./afl-harness @@
+   $ $AFLPATH/afl-fuzz -t 1000 -i testcase_dir -o findings_dir -- ./afl-harness
 
 Please see AFL documentation for more information.
index 102566c22d4d01ab0c15ce7b9eb42e6f4e052237..89d8605feab812ec4f6df891323b9756aee7f538 100644 (file)
@@ -14,7 +14,7 @@ static uint8_t input[INPUT_SIZE];
 int main(int argc, char **argv)
 {
     size_t size;
-    FILE *fp;
+    FILE *fp = NULL;
 
     setbuf(stdout, NULL);
 
@@ -40,6 +40,7 @@ int main(int argc, char **argv)
             break;
 
         case '?':
+        usage:
             printf("Usage: %s $FILE | [--min-input-size]\n", argv[0]);
             exit(-1);
             break;
@@ -51,17 +52,19 @@ int main(int argc, char **argv)
         }
     }
 
-    if ( optind != (argc - 1) )
-    {
-        printf("Expecting only one argument\n");
-        exit(-1);
-    }
+    if ( optind == argc ) /* No positional parameters.  Use stdin. */
+        fp = stdin;
+    else if ( optind != (argc - 1) )
+        goto usage;
 
-    fp = fopen(argv[1], "rb");
-    if ( fp == NULL )
+    if ( fp != stdin ) /* If not using stdin, open the provided file. */
     {
-        perror("fopen");
-        exit(-1);
+        fp = fopen(argv[optind], "rb");
+        if ( fp == NULL )
+        {
+            perror("fopen");
+            exit(-1);
+        }
     }
 
     size = fread(input, 1, INPUT_SIZE, fp);
@@ -78,7 +81,11 @@ int main(int argc, char **argv)
         exit(-1);
     }
 
-    fclose(fp);
+    if ( fp != stdin )
+    {
+        fclose(fp);
+        fp = NULL;
+    }
 
     LLVMFuzzerTestOneInput(input, size);