fuzz_descriptor.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/nodelist/torcert.h"
  10. #include "feature/keymgt/loadkey.h"
  11. #include "test/fuzz/fuzzing.h"
  12. static int
  13. mock_check_tap_onion_key_crosscert__nocheck(const uint8_t *crosscert,
  14. int crosscert_len,
  15. const crypto_pk_t *onion_pkey,
  16. const ed25519_public_key_t *master_id_pkey,
  17. const uint8_t *rsa_id_digest)
  18. {
  19. tor_assert(crosscert && onion_pkey && master_id_pkey && rsa_id_digest);
  20. /* we could look at crosscert[..] */
  21. (void) crosscert_len;
  22. return 0;
  23. }
  24. static void
  25. mock_dump_desc__nodump(const char *desc, const char *type)
  26. {
  27. (void)desc;
  28. (void)type;
  29. }
  30. static int
  31. mock_router_produce_hash_final__nohash(char *digest,
  32. const char *start, size_t len,
  33. digest_algorithm_t alg)
  34. {
  35. (void)start;
  36. (void)len;
  37. /* we could look at start[..] */
  38. if (alg == DIGEST_SHA1)
  39. memset(digest, 0x01, 20);
  40. else
  41. memset(digest, 0x02, 32);
  42. return 0;
  43. }
  44. int
  45. fuzz_init(void)
  46. {
  47. disable_signature_checking();
  48. MOCK(check_tap_onion_key_crosscert,
  49. mock_check_tap_onion_key_crosscert__nocheck);
  50. MOCK(dump_desc, mock_dump_desc__nodump);
  51. MOCK(router_compute_hash_final, mock_router_produce_hash_final__nohash);
  52. ed25519_init();
  53. return 0;
  54. }
  55. int
  56. fuzz_cleanup(void)
  57. {
  58. return 0;
  59. }
  60. int
  61. fuzz_main(const uint8_t *data, size_t sz)
  62. {
  63. routerinfo_t *ri;
  64. const char *str = (const char*) data;
  65. ri = router_parse_entry_from_string((const char *)str,
  66. str+sz,
  67. 0, 0, 0, NULL);
  68. if (ri) {
  69. log_debug(LD_GENERAL, "Parsing okay");
  70. routerinfo_free(ri);
  71. } else {
  72. log_debug(LD_GENERAL, "Parsing failed");
  73. }
  74. return 0;
  75. }