From 656ffa1b6da417475944c16720f2d2773c29d8d2 Mon Sep 17 00:00:00 2001 From: Alex Groce Date: Mon, 30 Jul 2018 22:05:56 -0700 Subject: [PATCH] new way to specify which test --- README.md | 4 ---- examples/CMakeLists.txt | 6 ------ src/lib/DeepState.c | 16 +++++++++------- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 2a76fcf..ab36939 100644 --- a/README.md +++ b/README.md @@ -99,10 +99,6 @@ directory shows how this can be done. The libFuzzer executable works like any other libFuzzer executable, and the tests produced can be run using the normal DeepState executable. -Because libFuzzer controls `main`, you need a different executable for -each test when using libFuzzer, which can be done as shown in the compilation for the -`IntegerOverflow` example. - ## Fuzzing with AFL DeepState can also be used with a file-based fuzzer (e.g. AFL). There diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index f873195..ab5ec63 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -71,12 +71,6 @@ if (BUILD_LIBFUZZER) target_link_libraries(IntegerOverflow_LF deepstate_LF) target_link_libraries (IntegerOverflow_LF "-fsanitize=fuzzer") set_target_properties(IntegerOverflow_LF PROPERTIES COMPILE_DEFINITIONS "LIBFUZZER") - - add_executable(IntegerOverflow_Addition_LF IntegerOverflow.cpp) - target_link_libraries(IntegerOverflow_Addition_LF deepstate_LF) - target_link_libraries (IntegerOverflow_Addition_LF "-fsanitize=fuzzer") - set_target_properties(IntegerOverflow_Addition_LF PROPERTIES COMPILE_DEFINITIONS - "LIBFUZZER;LIBFUZZER_WHICH_TEST=\"SignedInteger_AdditionOverflow\"") endif() add_executable(IntegerArithmetic IntegerArithmetic.cpp) diff --git a/src/lib/DeepState.c b/src/lib/DeepState.c index 3096fb5..99e7e51 100644 --- a/src/lib/DeepState.c +++ b/src/lib/DeepState.c @@ -558,15 +558,17 @@ extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { void *mem = malloc(sizeof(struct DeepState_TestRunInfo)); DeepState_CurrentTestRun = (struct DeepState_TestRunInfo *) mem; -#ifdef LIBFUZZER_WHICH_TEST - for (test = DeepState_FirstTest(); test != NULL; test = test->prev) { - if (strncmp(LIBFUZZER_WHICH_TEST, test->test_name, strlen(FLAGS_input_which_test)) == 0) { - break; + const char* which_test = getenv("LIBFUZZER_WHICH_TEST"); + if (!(strnlen(which_test, 1024) == 0)) { + for (test = DeepState_FirstTest(); test != NULL; test = test->prev) { + if (strncmp(which_test, test->test_name, strnlen(which_test, 1024)) == 0) { + break; + } } + } else + test = DeepState_FirstTest(); } -#else - test = DeepState_FirstTest(); -#endif + memset((void *) DeepState_Input, 0, sizeof(DeepState_Input)); DeepState_InputIndex = 0;