onefile.c 1.2 KB

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