diff options
-rw-r--r-- | src/fuzzer/fuzzers.h | 23 | ||||
-rw-r--r-- | src/fuzzer/invert.cpp | 18 | ||||
-rw-r--r-- | src/fuzzer/pkcs1.cpp | 19 | ||||
-rw-r--r-- | src/fuzzer/pow_mod.cpp | 11 | ||||
-rw-r--r-- | src/fuzzer/ressol.cpp | 9 |
5 files changed, 34 insertions, 46 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); diff --git a/src/fuzzer/invert.cpp b/src/fuzzer/invert.cpp index 08e8229b8..dd91fe83f 100644 --- a/src/fuzzer/invert.cpp +++ b/src/fuzzer/invert.cpp @@ -71,17 +71,13 @@ void fuzz(const uint8_t in[], size_t len) if(ref != ct) { - std::cout << "X = " << x << "\n"; - std::cout << "P = " << mod << "\n"; - std::cout << "GCD = " << gcd(x, mod) << "\n"; - std::cout << "Ref = " << ref << "\n"; - std::cout << "CT = " << ct << "\n"; - //std::cout << "Mon = " << mon << "\n"; - - std::cout << "RefCheck = " << (ref*ref)%mod << "\n"; - std::cout << "CTCheck = " << (ct*ct)%mod << "\n"; - //std::cout << "MonCheck = " << (mon*mon)%mod << "\n"; - abort(); + FUZZER_WRITE_AND_CRASH("X = " << x << "\n" + << "P = " << mod << "\n" + << "GCD = " << gcd(x, mod) << "\n" + << "Ref = " << ref << "\n" + << "CT = " << ct << "\n" + << "RefCheck = " << (ref*ref)%mod << "\n" + << "CTCheck = " << (ct*ct)%mod << "\n"); } } diff --git a/src/fuzzer/pkcs1.cpp b/src/fuzzer/pkcs1.cpp index a0323d2b2..8a297ff7f 100644 --- a/src/fuzzer/pkcs1.cpp +++ b/src/fuzzer/pkcs1.cpp @@ -51,7 +51,7 @@ void fuzz(const uint8_t in[], size_t len) else if(valid_mask == 0xFF) lib_rejected = false; else - abort(); + FUZZER_WRITE_AND_CRASH("Invalid valid_mask from unpad"); } catch(Botan::Decoding_Error&) { lib_rejected = true; } @@ -61,22 +61,15 @@ void fuzz(const uint8_t in[], size_t len) } catch(Botan::Decoding_Error& e) { ref_rejected = true; } - if(lib_rejected == ref_rejected) - { - return; // ok, they agree - } - - // otherwise: incorrect result, log info and crash if(lib_rejected == true && ref_rejected == false) { - std::cerr << "Library rejected input accepted by ref\n"; - std::cerr << "Ref decoded " << Botan::hex_encode(ref_result) << "\n"; + FUZZER_WRITE_AND_CRASH("Library rejected input accepted by ref " + << Botan::hex_encode(ref_result)); } else if(ref_rejected == true && lib_rejected == false) { - std::cerr << "Library accepted input reject by ref\n"; - std::cerr << "Lib decoded " << Botan::hex_encode(lib_result) << "\n"; + FUZZER_WRITE_AND_CRASH("Library accepted input rejected by ref " + << Botan::hex_encode(lib_result)); } - - abort(); + // otherwise the two implementations agree } diff --git a/src/fuzzer/pow_mod.cpp b/src/fuzzer/pow_mod.cpp index 2244c2004..e74902bd9 100644 --- a/src/fuzzer/pow_mod.cpp +++ b/src/fuzzer/pow_mod.cpp @@ -58,12 +58,11 @@ void fuzz(const uint8_t in[], size_t len) if(ref != z) { - std::cout << "G = " << g << "\n" - << "X = " << x << "\n" - << "P = " << p << "\n" - << "Z = " << z << "\n" - << "R = " << ref << "\n"; - abort(); + FUZZER_WRITE_AND_CRASH("G = " << g << "\n" + << "X = " << x << "\n" + << "P = " << p << "\n" + << "Z = " << z << "\n" + << "R = " << ref << "\n"); } } catch(Botan::Exception& e) {} diff --git a/src/fuzzer/ressol.cpp b/src/fuzzer/ressol.cpp index 17ba88b8b..99d48f98b 100644 --- a/src/fuzzer/ressol.cpp +++ b/src/fuzzer/ressol.cpp @@ -30,11 +30,10 @@ void fuzz(const uint8_t in[], size_t len) if(z != a_redc) { - std::cout << "A = " << a << "\n"; - std::cout << "P = " << p << "\n"; - std::cout << "R = " << a_sqrt << "\n"; - std::cout << "Z = " << z << "\n"; - abort(); + FUZZER_WRITE_AND_CRASH("A = " << a << "\n" + << "P = " << p << "\n" + << "R = " << a_sqrt << "\n" + << "Z = " << z << "\n"); } } } |