fuzz_extrainfo.c 1.3 KB

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