fuzzrunner.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (C) 2018 Sascha Brawer
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write see:
  16. * <http://www.gnu.org/licenses/>.
  17. */
  18. #include "config.h"
  19. #include "speech.h"
  20. #include <errno.h>
  21. #include <stdint.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <espeak-ng/espeak_ng.h>
  25. int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
  26. int main(int argc, char **argv) {
  27. int i;
  28. for (i = 1; i < argc; i++) {
  29. size_t filesize = GetFileLength(argv[i]);
  30. FILE *stream = fopen(argv[i], "r");
  31. unsigned char *text = NULL;
  32. if (stream == NULL) {
  33. perror(argv[i]);
  34. exit(EXIT_FAILURE);
  35. }
  36. text = (unsigned char *) malloc(filesize + 1);
  37. if (text == NULL) {
  38. espeak_ng_PrintStatusCodeMessage(ENOMEM, stderr, NULL);
  39. exit(EXIT_FAILURE);
  40. }
  41. fread(text, 1, filesize, stream);
  42. text[filesize] = 0;
  43. fclose(stream);
  44. LLVMFuzzerTestOneInput(text, filesize);
  45. free(text);
  46. }
  47. return EXIT_SUCCESS;
  48. }