fuzz_microdesc.c (1156B)
1 /* Copyright (c) 2016-2021, The Tor Project, Inc. */ 2 /* See LICENSE for licensing information */ 3 4 #include "core/or/or.h" 5 #include "feature/dirparse/microdesc_parse.h" 6 #include "feature/dirparse/unparseable.h" 7 #include "feature/nodelist/microdesc.h" 8 #include "lib/crypt_ops/crypto_ed25519.h" 9 10 #include "test/fuzz/fuzzing.h" 11 12 static void 13 mock_dump_desc__nodump(const char *desc, const char *type) 14 { 15 (void)desc; 16 (void)type; 17 } 18 19 int 20 fuzz_init(void) 21 { 22 disable_signature_checking(); 23 MOCK(dump_desc, mock_dump_desc__nodump); 24 ed25519_init(); 25 return 0; 26 } 27 28 int 29 fuzz_cleanup(void) 30 { 31 return 0; 32 } 33 34 int 35 fuzz_main(const uint8_t *data, size_t sz) 36 { 37 const char *str = (const char*) data; 38 smartlist_t *result = microdescs_parse_from_string((const char *)str, 39 str+sz, 40 0, SAVED_NOWHERE, NULL); 41 if (result) { 42 log_debug(LD_GENERAL, "Parsing okay: %d", smartlist_len(result)); 43 SMARTLIST_FOREACH(result, microdesc_t *, md, microdesc_free(md)); 44 smartlist_free(result); 45 } else { 46 log_debug(LD_GENERAL, "Parsing failed"); 47 } 48 return 0; 49 }