fuzz_descriptor.c 2.1 KB

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