fuzz_descriptor.c 2.0 KB

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