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