fuzz-harness.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "includes.h"
  2. #include "buffer.h"
  3. #include "dbutil.h"
  4. extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size);
  5. int main(int argc, char ** argv) {
  6. int i;
  7. buffer *input = buf_new(100000);
  8. int quiet = 0;
  9. for (i = 1; i < argc; i++) {
  10. #if DEBUG_TRACE
  11. if (strcmp(argv[i], "-v") == 0) {
  12. debug_trace++;
  13. fprintf(stderr, "debug level -> %d\n", debug_trace);
  14. }
  15. #endif
  16. if (strcmp(argv[i], "-q") == 0) {
  17. printf("Running quiet\n");
  18. quiet = 1;
  19. }
  20. }
  21. int old_fuzz_wrapfds = 0;
  22. for (i = 1; i < argc; i++) {
  23. if (argv[i][0] == '-') {
  24. /* ignore arguments */
  25. continue;
  26. }
  27. char* fn = argv[i];
  28. buf_setlen(input, 0);
  29. buf_readfile(input, fn);
  30. buf_setpos(input, 0);
  31. /* Run twice to catch problems with statefulness */
  32. fuzz.wrapfds = old_fuzz_wrapfds;
  33. if (!quiet) {
  34. printf("Running %s once \n", fn);
  35. }
  36. LLVMFuzzerTestOneInput(input->data, input->len);
  37. if (!quiet) {
  38. printf("Running %s twice \n", fn);
  39. }
  40. LLVMFuzzerTestOneInput(input->data, input->len);
  41. if (!quiet) {
  42. printf("Done %s\n", fn);
  43. }
  44. /* Disable wrapfd so it won't interfere with buf_readfile() above */
  45. old_fuzz_wrapfds = fuzz.wrapfds;
  46. fuzz.wrapfds = 0;
  47. }
  48. printf("Finished\n");
  49. return 0;
  50. }
  51. // Just to let it link
  52. size_t LLVMFuzzerMutate(uint8_t *UNUSED(Data), size_t UNUSED(Size), size_t UNUSED(MaxSize)) {
  53. printf("standalone fuzzer harness shouldn't call LLVMFuzzerMutate");
  54. abort();
  55. return 0;
  56. }