fuzz_microdesc.c 1.0 KB

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