fuzz_descriptor.c 1.8 KB

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