geom_gate userland utility improvements
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

75 lines
1.8 KiB

  1. #include <stdint.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include "testinput.h"
  5. /**
  6. * Main procedure for standalone fuzzing engine.
  7. *
  8. * Reads filenames from the argument array. For each filename, read the file
  9. * into memory and then call the fuzzing interface with the data.
  10. */
  11. int main(int argc, char **argv)
  12. {
  13. int ii;
  14. for(ii = 1; ii < argc; ii++)
  15. {
  16. FILE *infile;
  17. printf("[%s] ", argv[ii]);
  18. /* Try and open the file. */
  19. infile = fopen(argv[ii], "rb");
  20. if(infile)
  21. {
  22. uint8_t *buffer = NULL;
  23. size_t buffer_len;
  24. printf("Opened.. ");
  25. /* Get the length of the file. */
  26. fseek(infile, 0L, SEEK_END);
  27. buffer_len = ftell(infile);
  28. /* Reset the file indicator to the beginning of the file. */
  29. fseek(infile, 0L, SEEK_SET);
  30. /* Allocate a buffer for the file contents. */
  31. buffer = (uint8_t *)calloc(buffer_len, sizeof(uint8_t));
  32. if(buffer)
  33. {
  34. /* Read all the text from the file into the buffer. */
  35. fread(buffer, sizeof(uint8_t), buffer_len, infile);
  36. printf("Read %zu bytes, fuzzing.. ", buffer_len);
  37. /* Call the fuzzer with the data. */
  38. LLVMFuzzerTestOneInput(buffer, buffer_len);
  39. printf("complete !!");
  40. /* Free the buffer as it's no longer needed. */
  41. free(buffer);
  42. buffer = NULL;
  43. }
  44. else
  45. {
  46. fprintf(stderr,
  47. "[%s] Failed to allocate %zu bytes \n",
  48. argv[ii],
  49. buffer_len);
  50. }
  51. /* Close the file as it's no longer needed. */
  52. fclose(infile);
  53. infile = NULL;
  54. }
  55. else
  56. {
  57. /* Failed to open the file. Maybe wrong name or wrong permissions? */
  58. fprintf(stderr, "[%s] Open failed. \n", argv[ii]);
  59. }
  60. printf("\n");
  61. }
  62. }