fuzz_extrainfo.c 1.4 KB

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