fuzz_microdesc.c 1.1 KB

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