fuzz_extrainfo.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Copyright (c) 2016-2018, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #define ROUTERPARSE_PRIVATE
  4. #include "core/or/or.h"
  5. #include "feature/dirparse/routerparse.h"
  6. #include "feature/dirparse/unparseable.h"
  7. #include "feature/nodelist/routerlist.h"
  8. #include "feature/relay/routerkeys.h"
  9. #include "test/fuzz/fuzzing.h"
  10. static void
  11. mock_dump_desc__nodump(const char *desc, const char *type)
  12. {
  13. (void)desc;
  14. (void)type;
  15. }
  16. static int
  17. mock_router_produce_hash_final__nohash(char *digest,
  18. const char *start, size_t len,
  19. digest_algorithm_t alg)
  20. {
  21. (void)start;
  22. (void)len;
  23. /* we could look at start[..] */
  24. if (alg == DIGEST_SHA1)
  25. memset(digest, 0x01, 20);
  26. else
  27. memset(digest, 0x02, 32);
  28. return 0;
  29. }
  30. int
  31. fuzz_init(void)
  32. {
  33. disable_signature_checking();
  34. MOCK(dump_desc, mock_dump_desc__nodump);
  35. MOCK(router_compute_hash_final, mock_router_produce_hash_final__nohash);
  36. ed25519_init();
  37. return 0;
  38. }
  39. int
  40. fuzz_cleanup(void)
  41. {
  42. return 0;
  43. }
  44. int
  45. fuzz_main(const uint8_t *data, size_t sz)
  46. {
  47. extrainfo_t *ei;
  48. const char *str = (const char*) data;
  49. int again = 0;
  50. ei = extrainfo_parse_entry_from_string((const char *)str,
  51. str+sz,
  52. 0, NULL, &again);
  53. if (ei) {
  54. log_debug(LD_GENERAL, "Parsing okay");
  55. extrainfo_free(ei);
  56. } else {
  57. log_debug(LD_GENERAL, "Parsing failed");
  58. }
  59. return 0;
  60. }