fuzz_vrs.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Copyright (c) 2016-2017, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #define ROUTERPARSE_PRIVATE
  4. #define NETWORKSTATUS_PRIVATE
  5. #include "or.h"
  6. #include "routerparse.h"
  7. #include "memarea.h"
  8. #include "microdesc.h"
  9. #include "networkstatus.h"
  10. #include "fuzzing.h"
  11. static void
  12. mock_dump_desc__nodump(const char *desc, const char *type)
  13. {
  14. (void)desc;
  15. (void)type;
  16. }
  17. static networkstatus_t *dummy_vote = NULL;
  18. static memarea_t *area = NULL;
  19. int
  20. fuzz_init(void)
  21. {
  22. disable_signature_checking();
  23. MOCK(dump_desc, mock_dump_desc__nodump);
  24. ed25519_init();
  25. area = memarea_new();
  26. dummy_vote = tor_malloc_zero(sizeof(*dummy_vote));
  27. dummy_vote->known_flags = smartlist_new();
  28. smartlist_split_string(dummy_vote->known_flags,
  29. "Authority BadExit Exit Fast Guard HSDir "
  30. "NoEdConsensus Running Stable V2Dir Valid",
  31. " ", 0, 0);
  32. return 0;
  33. }
  34. int
  35. fuzz_cleanup(void)
  36. {
  37. SMARTLIST_FOREACH(dummy_vote->known_flags, char *, cp, tor_free(cp));
  38. smartlist_free(dummy_vote->known_flags);
  39. tor_free(dummy_vote);
  40. return 0;
  41. }
  42. int
  43. fuzz_main(const uint8_t *data, size_t sz)
  44. {
  45. char *str = tor_memdup_nulterm(data, sz);
  46. const char *s;
  47. routerstatus_t *rs_ns = NULL, *rs_md = NULL, *rs_vote = NULL;
  48. vote_routerstatus_t *vrs = tor_malloc_zero(sizeof(*vrs));
  49. smartlist_t *tokens = smartlist_new();
  50. s = str;
  51. rs_ns = routerstatus_parse_entry_from_string(area, &s, tokens,
  52. NULL, NULL, 26, FLAV_NS);
  53. tor_assert(smartlist_len(tokens) == 0);
  54. s = str;
  55. rs_md = routerstatus_parse_entry_from_string(area, &s, tokens,
  56. NULL, NULL, 26, FLAV_MICRODESC);
  57. tor_assert(smartlist_len(tokens) == 0);
  58. s = str;
  59. rs_vote = routerstatus_parse_entry_from_string(area, &s, tokens,
  60. dummy_vote, vrs, 26, FLAV_NS);
  61. tor_assert(smartlist_len(tokens) == 0);
  62. log_debug(LD_GENERAL,
  63. "ns=%p, md=%p, vote=%p", rs_ns, rs_md, rs_vote);
  64. routerstatus_free(rs_md);
  65. routerstatus_free(rs_ns);
  66. vote_routerstatus_free(vrs);
  67. memarea_clear(area);
  68. smartlist_free(tokens);
  69. tor_free(str);
  70. return 0;
  71. }