From ba6b172ee2e4c7b582ef4e4c12d07b101785e646 Mon Sep 17 00:00:00 2001 From: agroce Date: Thu, 13 Jun 2019 09:39:17 -0700 Subject: [PATCH] Fix crashes on failure to set up test from file --- src/include/deepstate/DeepState.h | 67 +++++++++++++++++-------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/src/include/deepstate/DeepState.h b/src/include/deepstate/DeepState.h index a85ce75..fe81a0c 100644 --- a/src/include/deepstate/DeepState.h +++ b/src/include/deepstate/DeepState.h @@ -648,41 +648,46 @@ extern enum DeepState_TestRunResult DeepState_FuzzOneTestCase(struct DeepState_T static enum DeepState_TestRunResult DeepState_RunSavedTestCase(struct DeepState_TestInfo *test, const char *dir, const char *name) { - size_t path_len = 2 + sizeof(char) * (strlen(dir) + strlen(name)); - char *path = (char *) malloc(path_len); - if (path == NULL) { - DeepState_Abandon("Error allocating memory"); - } - if (strncmp(dir, "", strlen(dir)) != 0) { - snprintf(path, path_len, "%s/%s", dir, name); - } else { - snprintf(path, path_len, "%s", name); - } - - DeepState_InitInputFromFile(path); - - DeepState_Begin(test); - - enum DeepState_TestRunResult result = DeepState_ForkAndRunTest(test); - - if (result == DeepState_TestRunFail) { - DeepState_LogFormat(DeepState_LogError, "Test case %s failed", path); - free(path); - } - else if (result == DeepState_TestRunCrash) { - DeepState_LogFormat(DeepState_LogError, "Crashed: %s", test->test_name); - DeepState_LogFormat(DeepState_LogError, "Test case %s crashed", path); - free(path); - if (HAS_FLAG_output_test_dir) { - DeepState_SaveCrashingTest(); + if (!setjmp(DeepState_ReturnToRun)) { + size_t path_len = 2 + sizeof(char) * (strlen(dir) + strlen(name)); + char *path = (char *) malloc(path_len); + if (path == NULL) { + DeepState_Abandon("Error allocating memory"); + } + if (strncmp(dir, "", strlen(dir)) != 0) { + snprintf(path, path_len, "%s/%s", dir, name); + } else { + snprintf(path, path_len, "%s", name); } - DeepState_Crash(); + DeepState_InitInputFromFile(path); + + DeepState_Begin(test); + + enum DeepState_TestRunResult result = DeepState_ForkAndRunTest(test); + + if (result == DeepState_TestRunFail) { + DeepState_LogFormat(DeepState_LogError, "Test case %s failed", path); + free(path); + } + else if (result == DeepState_TestRunCrash) { + DeepState_LogFormat(DeepState_LogError, "Crashed: %s", test->test_name); + DeepState_LogFormat(DeepState_LogError, "Test case %s crashed", path); + free(path); + if (HAS_FLAG_output_test_dir) { + DeepState_SaveCrashingTest(); + } + + DeepState_Crash(); + } else { + free(path); + } + + return result; } else { - free(path); + DeepState_LogFormat(DeepState_LogError, "Something went wrong running the test case %s", name); + return DeepState_TestRunCrash; } - - return result; } /* Run a single test many times, initialized against each saved test case in