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