From 032ae5ba4eba4dc8624fd9064cb40ee4a7fccaa7 Mon Sep 17 00:00:00 2001 From: agroce Date: Tue, 19 Feb 2019 18:17:45 +0000 Subject: [PATCH] truncate too-long tests with warning, rather than abort (better for fuzzers, nicer for replay) --- src/include/deepstate/DeepState.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/include/deepstate/DeepState.h b/src/include/deepstate/DeepState.h index e37626a..af181c6 100644 --- a/src/include/deepstate/DeepState.h +++ b/src/include/deepstate/DeepState.h @@ -483,20 +483,21 @@ static void DeepState_InitInputFromFile(const char *path) { DeepState_Abandon("Unable to access input file"); }; + size_t to_read = stat_buf.st_size; + if (stat_buf.st_size > sizeof(DeepState_Input)) { - DeepState_LogFormat(DeepState_LogInfo, "File too large; aborting"); - exit(255); // Don't make AFL think this is a crash! - // DeepState_Abandon("File too large"); + DeepState_LogFormat(DeepState_LogWarning, "File too large, truncating to max input size"); + to_read = DeepState_InputSize; } /* Reset the input buffer and reset the index. */ memset((void *) DeepState_Input, 0, sizeof(DeepState_Input)); DeepState_InputIndex = 0; - size_t count = fread((void *) DeepState_Input, 1, stat_buf.st_size, fp); + size_t count = fread((void *) DeepState_Input, 1, to_read, fp); fclose(fp); - if (count != stat_buf.st_size) { + if (count != to_read) { /* TODO(joe): Add error log with more info. */ DeepState_Abandon("Error reading file"); }