diff options
author | Nick Mathewson <nickm@torproject.org> | 2016-12-14 17:03:54 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-01-30 08:37:24 -0500 |
commit | 4afb155db2d9aaafe8dd1517e9619e6bd9c95751 (patch) | |
tree | 877839a98beba317fb072bb723623fb58cee38ff /src/test/fuzz/fuzz_microdesc.c | |
parent | 3c748559343b98f1dd37a0f49bd1e179715bf511 (diff) | |
download | tor-4afb155db2d9aaafe8dd1517e9619e6bd9c95751.tar.gz tor-4afb155db2d9aaafe8dd1517e9619e6bd9c95751.zip |
Add microdesc format fuzzer.
Diffstat (limited to 'src/test/fuzz/fuzz_microdesc.c')
-rw-r--r-- | src/test/fuzz/fuzz_microdesc.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/test/fuzz/fuzz_microdesc.c b/src/test/fuzz/fuzz_microdesc.c new file mode 100644 index 0000000000..bb944595fe --- /dev/null +++ b/src/test/fuzz/fuzz_microdesc.c @@ -0,0 +1,45 @@ +#define ROUTERPARSE_PRIVATE +#include "or.h" +#include "routerparse.h" +#include "microdesc.h" +#include "fuzzing.h" + +static void +mock_dump_desc__nodump(const char *desc, const char *type) +{ + (void)desc; + (void)type; +} + +int +fuzz_init(void) +{ + disable_signature_checking(); + MOCK(dump_desc, mock_dump_desc__nodump); + ed25519_init(); + return 0; +} + +int +fuzz_cleanup(void) +{ + return 0; +} + +int +fuzz_main(const uint8_t *data, size_t sz) +{ + const char *str = (const char*) data; + smartlist_t *result = microdescs_parse_from_string((const char *)str, + str+sz, + 0, SAVED_NOWHERE, NULL); + if (result) { + log_debug(LD_GENERAL, "Parsing okay: %d", smartlist_len(result)); + SMARTLIST_FOREACH(result, microdesc_t *, md, microdesc_free(md)); + smartlist_free(result); + } else { + log_debug(LD_GENERAL, "Parsing failed"); + } + return 0; +} + |