afl_driver.cpp 893 B

123456789101112131415161718192021222324252627
  1. // Lets AFL++ run the libFuzzer entry points of tools/fuzz/*.cpp: the forkserver starts after the sanitizers are
  2. // set up, every input is one fork. The target is built with clang's trace-pc-guard coverage and afl-compiler-rt.
  3. #include <cstddef>
  4. #include <cstdint>
  5. #include <sys/prctl.h>
  6. #include <unistd.h>
  7. #include <vector>
  8. extern "C" int LLVMFuzzerTestOneInput (const uint8_t* data, size_t size);
  9. extern "C" void __afl_manual_init ();
  10. int main () {
  11. // AFL++ wants ASan to abort; a non dumpable process never reaches the host's core handler (systemd-coredump)
  12. prctl (PR_SET_DUMPABLE, 0);
  13. __afl_manual_init ();
  14. std::vector<uint8_t> input;
  15. uint8_t chunk[65536];
  16. ssize_t got;
  17. while ((got = read (0, chunk, sizeof (chunk))) > 0) {
  18. input.insert (input.end (), chunk, chunk + got);
  19. }
  20. LLVMFuzzerTestOneInput (input.data (), input.size ());
  21. return 0;
  22. }