fuzz_microdesc.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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/nodelist/routerparse.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. }