diff mbox

[6/7] fuzz/x86emul: print out minimal input size

Message ID 20170125154416.3133-7-wei.liu2@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Wei Liu Jan. 25, 2017, 3:44 p.m. UTC
... so that users can know how big the initial input should be.

Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
 .../fuzz/x86_instruction_emulator/afl-x86-insn-emulator-fuzzer.c  | 8 ++++++++
 tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c    | 5 +++++
 2 files changed, 13 insertions(+)
diff mbox

Patch

diff --git a/tools/fuzz/x86_instruction_emulator/afl-x86-insn-emulator-fuzzer.c b/tools/fuzz/x86_instruction_emulator/afl-x86-insn-emulator-fuzzer.c
index b5668c11e7..655315f9c1 100644
--- a/tools/fuzz/x86_instruction_emulator/afl-x86-insn-emulator-fuzzer.c
+++ b/tools/fuzz/x86_instruction_emulator/afl-x86-insn-emulator-fuzzer.c
@@ -2,8 +2,10 @@ 
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 extern int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size);
+extern unsigned int fuzz_minimal_input_size(void);
 
 #define INPUT_SIZE  4096
 static uint8_t input[INPUT_SIZE];
@@ -19,6 +21,12 @@  int main(int argc, char **argv)
         exit(-1);
     }
 
+    if ( !strcmp(argv[1], "--min-input-size") )
+    {
+        printf("%u\n", fuzz_minimal_input_size());
+        exit(0);
+    }
+
     fp = fopen(argv[1], "rb");
     if ( fp == NULL )
     {
diff --git a/tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c b/tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c
index 8ca0421f60..3a731b28f2 100644
--- a/tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c
+++ b/tools/fuzz/x86_instruction_emulator/x86-insn-emulator-fuzzer.c
@@ -717,6 +717,11 @@  int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size)
     return 0;
 }
 
+unsigned int fuzz_minimal_input_size(void)
+{
+    return DATA_OFFSET + 1;
+}
+
 /*
  * Local variables:
  * mode: C