fuzz_microdesc.c 1.2 KB

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