fuzz_hsdescv2.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Copyright (c) 2016, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #define ROUTERPARSE_PRIVATE
  4. #include "or.h"
  5. #include "routerparse.h"
  6. #include "rendcommon.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. rend_service_descriptor_t *desc = NULL;
  31. char desc_id[64];
  32. char *ipts = NULL;
  33. size_t ipts_size, esize;
  34. const char *next;
  35. char *str = tor_memdup_nulterm(data, sz);
  36. (void) rend_parse_v2_service_descriptor(&desc, desc_id, &ipts, &ipts_size,
  37. &esize, &next, str, 1);
  38. if (desc) {
  39. log_debug(LD_GENERAL, "Parsing okay");
  40. rend_service_descriptor_free(desc);
  41. } else {
  42. log_debug(LD_GENERAL, "Parsing failed");
  43. }
  44. tor_free(ipts);
  45. tor_free(str);
  46. return 0;
  47. }