fuzz_main.c 992 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <stdint.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); /* required by C89 */
  5. /* fuzz target entry point, works without libFuzzer */
  6. int main(int argc, char **argv)
  7. {
  8. FILE *f;
  9. char *buf = NULL;
  10. long siz_buf;
  11. if(argc < 2)
  12. {
  13. fprintf(stderr, "no input file\n");
  14. goto err;
  15. }
  16. f = fopen(argv[1], "rb");
  17. if(f == NULL)
  18. {
  19. fprintf(stderr, "error opening input file %s\n", argv[1]);
  20. goto err;
  21. }
  22. fseek(f, 0, SEEK_END);
  23. siz_buf = ftell(f);
  24. rewind(f);
  25. if(siz_buf < 1) goto err;
  26. buf = (char*)malloc((size_t)siz_buf);
  27. if(buf == NULL)
  28. {
  29. fprintf(stderr, "malloc() failed\n");
  30. goto err;
  31. }
  32. if(fread(buf, (size_t)siz_buf, 1, f) != 1)
  33. {
  34. fprintf(stderr, "fread() failed\n");
  35. goto err;
  36. }
  37. (void)LLVMFuzzerTestOneInput((uint8_t*)buf, (size_t)siz_buf);
  38. err:
  39. free(buf);
  40. return 0;
  41. }