Skip to content

Commit

Permalink
[fuzz] Use afl++ shared-memory fuzzing
Browse files Browse the repository at this point in the history
  • Loading branch information
dergoegge committed Sep 12, 2023
1 parent fd69ffb commit 97e2e1d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/test/fuzz/fuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#include <utility>
#include <vector>

#ifdef __AFL_FUZZ_INIT
__AFL_FUZZ_INIT();
#endif

const std::function<void(const std::string&)> G_TEST_LOG_FUN{};

/**
Expand Down Expand Up @@ -188,7 +192,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();
Expand All @@ -197,12 +201,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<uint8_t> 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<uint8_t> buffer;
Expand Down

0 comments on commit 97e2e1d

Please sign in to comment.