From e18a26896a06b520c302b2031300cccc91f89855 Mon Sep 17 00:00:00 2001 From: Alex Groce Date: Fri, 27 Jul 2018 16:46:18 -0700 Subject: [PATCH] just read the data and run, abort if too large --- src/include/deepstate/DeepState.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/include/deepstate/DeepState.h b/src/include/deepstate/DeepState.h index 5020c67..aa363f4 100644 --- a/src/include/deepstate/DeepState.h +++ b/src/include/deepstate/DeepState.h @@ -720,6 +720,35 @@ static int DeepState_RunSavedTestCases(void) { } extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { + if (Size > sizeof(DeepState_Input)) { + return 0; // Just ignore any too-big inputs + } + + struct DeepState_TestInfo *test = NULL; + + DeepState_Setup(); + +#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; + } + } +#else + test = DeepState_FirstTest(); +#endif + + memset((void *) DeepState_Input, 0, sizeof(DeepState_Input)); + DeepState_InputIndex = 0; + + memcpy((void *) DeepState_Input, (void *) Data, Size); + + DeepState_Begin(test); + + enum DeepState_TestRunResult result = DeepState_ForkAndRunTest(test); + + DeepState_Teardown(); + return 0; // Non-zero return values are reserved for future use. }