diff --git a/src/test/fuzz/fuzz.cpp b/src/test/fuzz/fuzz.cpp index e093f80cee..8319a8f52d 100644 --- a/src/test/fuzz/fuzz.cpp +++ b/src/test/fuzz/fuzz.cpp @@ -22,6 +22,10 @@ #include #include +#ifdef __AFL_FUZZ_INIT +__AFL_FUZZ_INIT(); +#endif + const std::function G_TEST_LOG_FUN{}; /** @@ -166,7 +170,7 @@ int main(int argc, char** argv) { initialize(); static const auto& test_one_input = *Assert(g_test_one_input); -#ifdef __AFL_INIT +#ifdef __AFL_HAVE_MANUAL_CONTROL // Enable AFL deferred forkserver mode. Requires compilation using // afl-clang-fast++. See fuzzing.md for details. __AFL_INIT(); @@ -175,12 +179,10 @@ int main(int argc, char** argv) #ifdef __AFL_LOOP // Enable AFL persistent mode. Requires compilation using afl-clang-fast++. // See fuzzing.md for details. + const uint8_t* buffer = __AFL_FUZZ_TESTCASE_BUF; while (__AFL_LOOP(1000)) { - std::vector buffer; - if (!read_stdin(buffer)) { - continue; - } - test_one_input(buffer); + size_t buffer_len = __AFL_FUZZ_TESTCASE_LEN; + test_one_input({buffer, buffer_len}); } #else std::vector buffer;