diff options
author | Jack Lloyd <[email protected]> | 2017-09-02 08:21:58 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-09-02 08:21:58 -0400 |
commit | 4d8d8594b7a75675a19b7feec8fd917b92ec0edd (patch) | |
tree | 525daf1ac9aaec38403b1ef864ff2942c16a6c57 /src/fuzzer/fuzzers.h | |
parent | bc7608874cf7ec4aef35a6e693dbbbf79c83b519 (diff) |
Clean up fuzzer code a bit
If we ever output something to the terminal it should be because
we are crashing.
Diffstat (limited to 'src/fuzzer/fuzzers.h')
-rw-r--r-- | src/fuzzer/fuzzers.h | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/fuzzer/fuzzers.h b/src/fuzzer/fuzzers.h index d0e6b85f5..caade8a13 100644 --- a/src/fuzzer/fuzzers.h +++ b/src/fuzzer/fuzzers.h @@ -14,13 +14,10 @@ #include <botan/exceptn.h> #include <botan/chacha_rng.h> -#if defined(BOTAN_FUZZER_IS_AFL) && !defined(__AFL_COMPILER) - #error "Build configured for AFL but not being compiled by AFL compiler" -#endif - static const size_t max_fuzzer_input_size = 8192; extern void fuzz(const uint8_t in[], size_t len); + extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv); extern "C" int LLVMFuzzerTestOneInput(const uint8_t in[], size_t len); @@ -52,25 +49,29 @@ inline Botan::RandomNumberGenerator& fuzzer_rng() return rng; } +#define FUZZER_WRITE_AND_CRASH(expr) \ + do { std::cerr << expr; abort(); } while(0) + #define FUZZER_ASSERT_EQUAL(x, y) do { \ if(x != y) { \ - std::cerr << #x << " = " << x << " !=\n" << #y << " = " << y \ - << " at " << __LINE__ << ":" << __FILE__ << std::endl; \ - abort(); \ -} } while(0) + FUZZER_WRITE_AND_CRASH(#x << " = " << x << " !=\n" \ + << #y << " = " << y << "\n"); \ + } } while(0) #define FUZZER_ASSERT_TRUE(e) \ do { \ if(!(e)) { \ - std::cerr << "Expression " << #e << " was false at " \ - << __LINE__ << ":" << __FILE__ << std::endl; \ - abort(); \ + FUZZER_WRITE_AND_CRASH("Expression " << #e << " was false"); \ } } while(0) #if defined(BOTAN_FUZZER_IS_AFL) || defined(BOTAN_FUZZER_IS_TEST) /* Stub for AFL */ +#if defined(BOTAN_FUZZER_IS_AFL) && !defined(__AFL_COMPILER) + #error "Build configured for AFL but not being compiled by AFL compiler" +#endif + int main(int argc, char* argv[]) { LLVMFuzzerInitialize(&argc, &argv); |