fuzz_extrainfo.c 1.5 KB

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