Skip to content

Commit 858d313

Browse files
committed
Merge bitcoin/bitcoin#28460: fuzz: Use afl++ shared-memory fuzzing
97e2e1d [fuzz] Use afl++ shared-memory fuzzing (dergoegge) Pull request description: Using shared-memory is faster than reading from stdin, see https://github.com/AFLplusplus/AFLplusplus/blob/7d2122e0596132f9344a5d0896020ebc79cd33db/instrumentation/README.persistent_mode.md ACKs for top commit: MarcoFalke: review ACK 97e2e1d Tree-SHA512: 7e71b5f84835e41531c19ee959be2426da245869757de8e5dd1c730ae83ead650e2ef75f4d594d7965f661821a4ffbd27be84d3ce623702991501b34a8d02fc3
2 parents 9e9206f + 97e2e1d commit 858d313

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/test/fuzz/fuzz.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#include <utility>
3030
#include <vector>
3131

32+
#ifdef __AFL_FUZZ_INIT
33+
__AFL_FUZZ_INIT();
34+
#endif
35+
3236
const std::function<void(const std::string&)> G_TEST_LOG_FUN{};
3337

3438
/**
@@ -188,7 +192,7 @@ int main(int argc, char** argv)
188192
{
189193
initialize();
190194
static const auto& test_one_input = *Assert(g_test_one_input);
191-
#ifdef __AFL_INIT
195+
#ifdef __AFL_HAVE_MANUAL_CONTROL
192196
// Enable AFL deferred forkserver mode. Requires compilation using
193197
// afl-clang-fast++. See fuzzing.md for details.
194198
__AFL_INIT();
@@ -197,12 +201,10 @@ int main(int argc, char** argv)
197201
#ifdef __AFL_LOOP
198202
// Enable AFL persistent mode. Requires compilation using afl-clang-fast++.
199203
// See fuzzing.md for details.
204+
const uint8_t* buffer = __AFL_FUZZ_TESTCASE_BUF;
200205
while (__AFL_LOOP(1000)) {
201-
std::vector<uint8_t> buffer;
202-
if (!read_stdin(buffer)) {
203-
continue;
204-
}
205-
test_one_input(buffer);
206+
size_t buffer_len = __AFL_FUZZ_TESTCASE_LEN;
207+
test_one_input({buffer, buffer_len});
206208
}
207209
#else
208210
std::vector<uint8_t> buffer;

0 commit comments

Comments
 (0)