onefile.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <stdint.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. /* This file doesn't use any Mbed TLS function, but grab mbedtls_config.h anyway
  5. * in case it contains platform-specific #defines related to malloc or
  6. * stdio functions. */
  7. #include "mbedtls/build_info.h"
  8. int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
  9. int main(int argc, char **argv)
  10. {
  11. FILE *fp;
  12. uint8_t *Data;
  13. size_t Size;
  14. if (argc != 2) {
  15. return 1;
  16. }
  17. //opens the file, get its size, and reads it into a buffer
  18. fp = fopen(argv[1], "rb");
  19. if (fp == NULL) {
  20. return 2;
  21. }
  22. if (fseek(fp, 0L, SEEK_END) != 0) {
  23. fclose(fp);
  24. return 2;
  25. }
  26. Size = ftell(fp);
  27. if (Size == (size_t) -1) {
  28. fclose(fp);
  29. return 2;
  30. }
  31. if (fseek(fp, 0L, SEEK_SET) != 0) {
  32. fclose(fp);
  33. return 2;
  34. }
  35. Data = malloc(Size);
  36. if (Data == NULL) {
  37. fclose(fp);
  38. return 2;
  39. }
  40. if (fread(Data, Size, 1, fp) != 1) {
  41. free(Data);
  42. fclose(fp);
  43. return 2;
  44. }
  45. //launch fuzzer
  46. LLVMFuzzerTestOneInput(Data, Size);
  47. free(Data);
  48. fclose(fp);
  49. return 0;
  50. }