fuzz_vrs.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 "networkstatus_st.h"
  11. #include "vote_routerstatus_st.h"
  12. #include "fuzzing.h"
  13. static void
  14. mock_dump_desc__nodump(const char *desc, const char *type)
  15. {
  16. (void)desc;
  17. (void)type;
  18. }
  19. static networkstatus_t *dummy_vote = NULL;
  20. static memarea_t *area = NULL;
  21. int
  22. fuzz_init(void)
  23. {
  24. disable_signature_checking();
  25. MOCK(dump_desc, mock_dump_desc__nodump);
  26. ed25519_init();
  27. area = memarea_new();
  28. dummy_vote = tor_malloc_zero(sizeof(*dummy_vote));
  29. dummy_vote->known_flags = smartlist_new();
  30. smartlist_split_string(dummy_vote->known_flags,
  31. "Authority BadExit Exit Fast Guard HSDir "
  32. "NoEdConsensus Running Stable V2Dir Valid",
  33. " ", 0, 0);
  34. return 0;
  35. }
  36. int
  37. fuzz_cleanup(void)
  38. {
  39. SMARTLIST_FOREACH(dummy_vote->known_flags, char *, cp, tor_free(cp));
  40. smartlist_free(dummy_vote->known_flags);
  41. tor_free(dummy_vote);
  42. return 0;
  43. }
  44. int
  45. fuzz_main(const uint8_t *data, size_t sz)
  46. {
  47. char *str = tor_memdup_nulterm(data, sz);
  48. const char *s;
  49. routerstatus_t *rs_ns = NULL, *rs_md = NULL, *rs_vote = NULL;
  50. vote_routerstatus_t *vrs = tor_malloc_zero(sizeof(*vrs));
  51. smartlist_t *tokens = smartlist_new();
  52. s = str;
  53. rs_ns = routerstatus_parse_entry_from_string(area, &s, tokens,
  54. NULL, NULL, 26, FLAV_NS);
  55. tor_assert(smartlist_len(tokens) == 0);
  56. s = str;
  57. rs_md = routerstatus_parse_entry_from_string(area, &s, tokens,
  58. NULL, NULL, 26, FLAV_MICRODESC);
  59. tor_assert(smartlist_len(tokens) == 0);
  60. s = str;
  61. rs_vote = routerstatus_parse_entry_from_string(area, &s, tokens,
  62. dummy_vote, vrs, 26, FLAV_NS);
  63. tor_assert(smartlist_len(tokens) == 0);
  64. log_debug(LD_GENERAL,
  65. "ns=%p, md=%p, vote=%p", rs_ns, rs_md, rs_vote);
  66. routerstatus_free(rs_md);
  67. routerstatus_free(rs_ns);
  68. vote_routerstatus_free(vrs);
  69. memarea_clear(area);
  70. smartlist_free(tokens);
  71. tor_free(str);
  72. return 0;
  73. }