Skip to content

Commit

Permalink
bitcoin#18008: only declare a main() when fuzzing with AFL
Browse files Browse the repository at this point in the history
  • Loading branch information
kwvg committed Aug 2, 2021
1 parent 251eece commit de95ae3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/test/fuzz/fuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <unistd.h>
#include <vector>

#if defined(__AFL_COMPILER)
static bool read_stdin(std::vector<uint8_t>& data)
{
uint8_t buffer[1024];
Expand All @@ -19,6 +20,7 @@ static bool read_stdin(std::vector<uint8_t>& data)
}
return length == 0;
}
#endif

// Default initialization: Override using a non-weak initialize().
__attribute__((weak)) void initialize()
Expand All @@ -40,9 +42,9 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
return 0;
}

// Declare main(...) "weak" to allow for libFuzzer linking. libFuzzer provides
// the main(...) function.
__attribute__((weak)) int main(int argc, char** argv)
// Generally, the fuzzer will provide main(), except for AFL
#if defined(__AFL_COMPILER)
int main(int argc, char** argv)
{
initialize();
#ifdef __AFL_INIT
Expand Down Expand Up @@ -70,3 +72,4 @@ __attribute__((weak)) int main(int argc, char** argv)
#endif
return 0;
}
#endif

0 comments on commit de95ae3

Please sign in to comment.