fuzz_microdesc.c 946 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #define ROUTERPARSE_PRIVATE
  2. #include "or.h"
  3. #include "routerparse.h"
  4. #include "microdesc.h"
  5. #include "fuzzing.h"
  6. static void
  7. mock_dump_desc__nodump(const char *desc, const char *type)
  8. {
  9. (void)desc;
  10. (void)type;
  11. }
  12. int
  13. fuzz_init(void)
  14. {
  15. disable_signature_checking();
  16. MOCK(dump_desc, mock_dump_desc__nodump);
  17. ed25519_init();
  18. return 0;
  19. }
  20. int
  21. fuzz_cleanup(void)
  22. {
  23. return 0;
  24. }
  25. int
  26. fuzz_main(const uint8_t *data, size_t sz)
  27. {
  28. const char *str = (const char*) data;
  29. smartlist_t *result = microdescs_parse_from_string((const char *)str,
  30. str+sz,
  31. 0, SAVED_NOWHERE, NULL);
  32. if (result) {
  33. log_debug(LD_GENERAL, "Parsing okay: %d", smartlist_len(result));
  34. SMARTLIST_FOREACH(result, microdesc_t *, md, microdesc_free(md));
  35. smartlist_free(result);
  36. } else {
  37. log_debug(LD_GENERAL, "Parsing failed");
  38. }
  39. return 0;
  40. }