Skip to content

Commit 97e2e1d

Browse files
committed
[fuzz] Use afl++ shared-memory fuzzing
Using shared-memory is faster than reading from stdin, see https://github.com/AFLplusplus/AFLplusplus/blob/7d2122e0596132f9344a5d0896020ebc79cd33db/instrumentation/README.persistent_mode.md
1 parent fd69ffb commit 97e2e1d

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)