[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen master] tools/insn-fuzz: Make use of LLVMFuzzerInitialize()
commit 63092064eb1e6268357516715245a481db653e13 Author: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> AuthorDate: Wed Mar 1 18:46:52 2017 +0000 Commit: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> CommitDate: Mon Mar 20 16:45:21 2017 +0000 tools/insn-fuzz: Make use of LLVMFuzzerInitialize() libfuzz can perform one-time initialisation by calling LLVMFuzzerInitialize(). Move emul_test_init() into this, to avoid repeating it on every LLVMFuzzerTestOneInput() call. Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx> Reviewed-by: Wei Liu <wei.liu2@xxxxxxxxxx> --- tools/fuzz/x86_instruction_emulator/afl-harness.c | 4 ++++ tools/fuzz/x86_instruction_emulator/fuzz-emul.c | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tools/fuzz/x86_instruction_emulator/afl-harness.c b/tools/fuzz/x86_instruction_emulator/afl-harness.c index 89d8605..63aff59 100644 --- a/tools/fuzz/x86_instruction_emulator/afl-harness.c +++ b/tools/fuzz/x86_instruction_emulator/afl-harness.c @@ -5,6 +5,7 @@ #include <string.h> #include <getopt.h> +extern int LLVMFuzzerInitialize(int *argc, char ***argv); extern int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size); extern unsigned int fuzz_minimal_input_size(void); @@ -57,6 +58,9 @@ int main(int argc, char **argv) else if ( optind != (argc - 1) ) goto usage; + if ( LLVMFuzzerInitialize(&argc, &argv) ) + exit(-1); + if ( fp != stdin ) /* If not using stdin, open the provided file. */ { fp = fopen(argv[optind], "rb"); diff --git a/tools/fuzz/x86_instruction_emulator/fuzz-emul.c b/tools/fuzz/x86_instruction_emulator/fuzz-emul.c index 4b1e324..3b3041d 100644 --- a/tools/fuzz/x86_instruction_emulator/fuzz-emul.c +++ b/tools/fuzz/x86_instruction_emulator/fuzz-emul.c @@ -646,9 +646,19 @@ static void sanitize_input(struct x86_emulate_ctxt *ctxt) } } +int LLVMFuzzerInitialize(int *argc, char ***argv) +{ + if ( !emul_test_init() ) + { + printf("Warning: Stack could not be made executable (%d).\n", errno); + return 1; + } + + return 0; +} + int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size) { - bool stack_exec; struct cpu_user_regs regs = {}; struct x86_emulate_ctxt ctxt = { .regs = ®s, @@ -657,13 +667,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data_p, size_t size) }; int rc; - stack_exec = emul_test_init(); - if ( !stack_exec ) - { - printf("Warning: Stack could not be made executable (%d).\n", errno); - return 1; - } - /* Reset all global state variables */ memset(&input, 0, sizeof(input)); data_index = 0; -- generated by git-patchbot for /home/xen/git/xen.git#master _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxx https://lists.xenproject.org/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |