[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] tools/insn-fuzz: Use getopt() for parsing the command line



commit 6a6f3ff2c1254e2ed11a285cb9f4ecf6fe129acd
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Thu Mar 2 17:01:34 2017 +0000
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Mon Mar 20 16:45:20 2017 +0000

    tools/insn-fuzz: Use getopt() for parsing the command line
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 tools/fuzz/x86_instruction_emulator/afl-harness.c | 40 +++++++++++++++++++----
 1 file changed, 34 insertions(+), 6 deletions(-)

diff --git a/tools/fuzz/x86_instruction_emulator/afl-harness.c 
b/tools/fuzz/x86_instruction_emulator/afl-harness.c
index 16edbd6..102566c 100644
--- a/tools/fuzz/x86_instruction_emulator/afl-harness.c
+++ b/tools/fuzz/x86_instruction_emulator/afl-harness.c
@@ -3,6 +3,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <getopt.h>
 
 extern int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size);
 extern unsigned int fuzz_minimal_input_size(void);
@@ -17,16 +18,43 @@ int main(int argc, char **argv)
 
     setbuf(stdout, NULL);
 
-    if ( argc != 2 )
+    while ( 1 )
     {
-        printf("Expecting only one argument\n");
-        exit(-1);
+        enum {
+            OPT_MIN_SIZE,
+        };
+        static const struct option lopts[] = {
+            { "min-input-size", no_argument, NULL, OPT_MIN_SIZE },
+            { 0, 0, 0, 0 }
+        };
+        int c = getopt_long_only(argc, argv, "", lopts, NULL);
+
+        if ( c == -1 )
+            break;
+
+        switch ( c )
+        {
+        case OPT_MIN_SIZE:
+            printf("%u\n", fuzz_minimal_input_size());
+            exit(0);
+            break;
+
+        case '?':
+            printf("Usage: %s $FILE | [--min-input-size]\n", argv[0]);
+            exit(-1);
+            break;
+
+        default:
+            printf("Bad getopt return %d (%c)\n", c, c);
+            exit(-1);
+            break;
+        }
     }
 
-    if ( !strcmp(argv[1], "--min-input-size") )
+    if ( optind != (argc - 1) )
     {
-        printf("%u\n", fuzz_minimal_input_size());
-        exit(0);
+        printf("Expecting only one argument\n");
+        exit(-1);
     }
 
     fp = fopen(argv[1], "rb");
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.