summaryrefslogtreecommitdiff
path: root/src/test/fuzz/fuzz_extrainfo.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-12-14 10:05:41 -0500
committerNick Mathewson <nickm@torproject.org>2017-01-30 08:37:24 -0500
commit81e44c22573e86cdcca6e47a7e68b3c83d4855f1 (patch)
tree1b2bd572b88c95594d0837fc67acc8562197b0f8 /src/test/fuzz/fuzz_extrainfo.c
parent44fa14c0e28ac26a551169d5621648db9bc08da9 (diff)
downloadtor-81e44c22573e86cdcca6e47a7e68b3c83d4855f1.tar.gz
tor-81e44c22573e86cdcca6e47a7e68b3c83d4855f1.zip
Add extrainfo fuzzer
Diffstat (limited to 'src/test/fuzz/fuzz_extrainfo.c')
-rw-r--r--src/test/fuzz/fuzz_extrainfo.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/test/fuzz/fuzz_extrainfo.c b/src/test/fuzz/fuzz_extrainfo.c
new file mode 100644
index 0000000000..6bfc425a9a
--- /dev/null
+++ b/src/test/fuzz/fuzz_extrainfo.c
@@ -0,0 +1,63 @@
+#define ROUTERPARSE_PRIVATE
+#include "or.h"
+#include "routerparse.h"
+#include "routerlist.h"
+#include "routerkeys.h"
+#include "fuzzing.h"
+
+static void
+mock_dump_desc__nodump(const char *desc, const char *type)
+{
+ (void)desc;
+ (void)type;
+}
+
+static int
+mock_router_produce_hash_final__nohash(char *digest,
+ const char *start, size_t len,
+ digest_algorithm_t alg)
+{
+ (void)start;
+ (void)len;
+ /* we could look at start[..] */
+ if (alg == DIGEST_SHA1)
+ memset(digest, 0x01, 20);
+ else
+ memset(digest, 0x02, 32);
+ return 0;
+}
+
+int
+fuzz_init(void)
+{
+ disable_signature_checking();
+ MOCK(dump_desc, mock_dump_desc__nodump);
+ MOCK(router_compute_hash_final, mock_router_produce_hash_final__nohash);
+ ed25519_init();
+ return 0;
+}
+
+int
+fuzz_cleanup(void)
+{
+ return 0;
+}
+
+int
+fuzz_main(const uint8_t *data, size_t sz)
+{
+ extrainfo_t *ei;
+ const char *str = (const char*) data;
+ int again = 0;
+ ei = extrainfo_parse_entry_from_string((const char *)str,
+ str+sz,
+ 0, NULL, &again);
+ if (ei) {
+ log_debug(LD_GENERAL, "Parsing okay");
+ extrainfo_free(ei);
+ } else {
+ log_debug(LD_GENERAL, "Parsing failed");
+ }
+ return 0;
+}
+