Merge pull request #127 from trailofbits/ranges_for_fuzzing
simple fix for libFuzzer ranges
This commit is contained in:
@@ -235,7 +235,11 @@ DEEPSTATE_INLINE static void DeepState_Check(int expr) {
|
||||
DEEPSTATE_INLINE static tname DeepState_ ## Tname ## InRange( \
|
||||
tname low, tname high) { \
|
||||
tname x = DeepState_ ## Tname(); \
|
||||
(void) DeepState_Assume(low <= x && x <= high); \
|
||||
if (!(DeepState_UsingLibFuzzer || HAS_FLAG_input_test_file \
|
||||
|| HAS_FLAG_input_test_dir || HAS_FLAG_input_test_files_dir)) \
|
||||
(void) DeepState_Assume(low <= x && x <= high); \
|
||||
else \
|
||||
x = low + (x%((high+1)-low)); \
|
||||
return x; \
|
||||
}
|
||||
|
||||
|
||||
@@ -298,6 +298,9 @@ int32_t DeepState_MaxInt(int32_t v) {
|
||||
void _DeepState_Assume(int expr, const char *expr_str, const char *file,
|
||||
unsigned line) {
|
||||
if (!expr) {
|
||||
DeepState_LogFormat(DeepState_LogError,
|
||||
"%s(%u): Assumption %s failed",
|
||||
file, line, expr_str);
|
||||
DeepState_Abandon("Assumption failed");
|
||||
}
|
||||
}
|
||||
@@ -598,6 +601,13 @@ extern int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
||||
|
||||
enum DeepState_TestRunResult result = DeepState_RunTestLLVM(test);
|
||||
|
||||
const char* abort_check = getenv("LIBFUZZER_ABORT_ON_FAIL");
|
||||
if (abort_check != NULL) {
|
||||
if ((result == DeepState_TestRunFail) || (result == DeepState_TestRunCrash)) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
DeepState_Teardown();
|
||||
DeepState_CurrentTestRun = NULL;
|
||||
free(mem);
|
||||
|
||||
Reference in New Issue
Block a user