fuzz_vrs.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Copyright (c) 2016, 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. tor_free(dummy_vote);
  38. return 0;
  39. }
  40. int
  41. fuzz_main(const uint8_t *data, size_t sz)
  42. {
  43. const char *str = tor_memdup_nulterm(data, sz), *s;
  44. routerstatus_t *rs_ns = NULL, *rs_md = NULL, *rs_vote = NULL;
  45. vote_routerstatus_t *vrs = tor_malloc_zero(sizeof(*vrs));
  46. smartlist_t *tokens = smartlist_new();
  47. s = str;
  48. rs_ns = routerstatus_parse_entry_from_string(area, &s, tokens,
  49. NULL, NULL, 26, FLAV_NS);
  50. tor_assert(smartlist_len(tokens) == 0);
  51. s = str;
  52. rs_md = routerstatus_parse_entry_from_string(area, &s, tokens,
  53. NULL, NULL, 26, FLAV_MICRODESC);
  54. tor_assert(smartlist_len(tokens) == 0);
  55. s = str;
  56. rs_vote = routerstatus_parse_entry_from_string(area, &s, tokens,
  57. dummy_vote, vrs, 26, FLAV_NS);
  58. tor_assert(smartlist_len(tokens) == 0);
  59. log_debug(LD_GENERAL,
  60. "ns=%p, md=%p, vote=%p", rs_ns, rs_md, rs_vote);
  61. routerstatus_free(rs_md);
  62. routerstatus_free(rs_ns);
  63. vote_routerstatus_free(vrs);
  64. memarea_clear(area);
  65. smartlist_free(tokens);
  66. return 0;
  67. }