fuzz_vrs.c 2.1 KB

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