mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-05 10:42:13 +02:00
[fuzz] Use afl++ shared-memory fuzzing
Using shared-memory is faster than reading from stdin, see
7d2122e059/instrumentation/README.persistent_mode.md
This commit is contained in:
@@ -29,6 +29,10 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#ifdef __AFL_FUZZ_INIT
|
||||||
|
__AFL_FUZZ_INIT();
|
||||||
|
#endif
|
||||||
|
|
||||||
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
|
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -188,7 +192,7 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
initialize();
|
initialize();
|
||||||
static const auto& test_one_input = *Assert(g_test_one_input);
|
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
|
// Enable AFL deferred forkserver mode. Requires compilation using
|
||||||
// afl-clang-fast++. See fuzzing.md for details.
|
// afl-clang-fast++. See fuzzing.md for details.
|
||||||
__AFL_INIT();
|
__AFL_INIT();
|
||||||
@@ -197,12 +201,10 @@ int main(int argc, char** argv)
|
|||||||
#ifdef __AFL_LOOP
|
#ifdef __AFL_LOOP
|
||||||
// Enable AFL persistent mode. Requires compilation using afl-clang-fast++.
|
// Enable AFL persistent mode. Requires compilation using afl-clang-fast++.
|
||||||
// See fuzzing.md for details.
|
// See fuzzing.md for details.
|
||||||
|
const uint8_t* buffer = __AFL_FUZZ_TESTCASE_BUF;
|
||||||
while (__AFL_LOOP(1000)) {
|
while (__AFL_LOOP(1000)) {
|
||||||
std::vector<uint8_t> buffer;
|
size_t buffer_len = __AFL_FUZZ_TESTCASE_LEN;
|
||||||
if (!read_stdin(buffer)) {
|
test_one_input({buffer, buffer_len});
|
||||||
continue;
|
|
||||||
}
|
|
||||||
test_one_input(buffer);
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
std::vector<uint8_t> buffer;
|
std::vector<uint8_t> buffer;
|
||||||
|
|||||||
Reference in New Issue
Block a user