summaryrefslogtreecommitdiff
path: root/src/test/fuzz/fuzzing_common.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-12-13 19:15:26 -0500
committerNick Mathewson <nickm@torproject.org>2016-12-19 15:34:55 -0500
commitb96c70d668f96550401057834bb9caafb5d0e412 (patch)
tree28ebfdf7347eebf92e9b3716baca1d10fcbd3b9a /src/test/fuzz/fuzzing_common.c
parentfca91a7793f24fc5f2d043167317fd47dd58f1ed (diff)
downloadtor-b96c70d668f96550401057834bb9caafb5d0e412.tar.gz
tor-b96c70d668f96550401057834bb9caafb5d0e412.zip
Fuzzing: Add an initial fuzzing tool, for descriptors.
This will need some refactoring and mocking.
Diffstat (limited to 'src/test/fuzz/fuzzing_common.c')
-rw-r--r--src/test/fuzz/fuzzing_common.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/test/fuzz/fuzzing_common.c b/src/test/fuzz/fuzzing_common.c
new file mode 100644
index 0000000000..51d519b861
--- /dev/null
+++ b/src/test/fuzz/fuzzing_common.c
@@ -0,0 +1,52 @@
+#include "orconfig.h"
+#include "torint.h"
+#include "util.h"
+#include "torlog.h"
+#include "backtrace.h"
+#include "fuzzing.h"
+
+extern const char tor_git_revision[];
+const char tor_git_revision[] = "";
+
+#define MAX_FUZZ_SIZE (128*1024)
+
+#ifdef LLVM_FUZZ
+int
+LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
+ static int initialized = 0;
+ if (!initialized) {
+ if (fuzz_init() < 0)
+ abort();
+ }
+
+ return fuzz_main(Data, Size);
+}
+
+#else /* Not LLVM_FUZZ, so AFL. */
+
+int
+main(int argc, char **argv)
+{
+ size_t size;
+ char *input = read_file_to_str_until_eof(0, MAX_FUZZ_SIZE, &size);
+
+ tor_threads_init();
+ init_logging(1);
+
+ if (argc > 1 && !strcmp(argv[1], "--info")) {
+ log_severity_list_t sev;
+ set_log_severity_config(LOG_INFO, LOG_ERR, &sev);
+ add_stream_log(&sev, "stdout", 1);
+ configure_backtrace_handler(NULL);
+ }
+
+ tor_assert(input);
+ if (fuzz_init() < 0)
+ abort();
+ fuzz_main((const uint8_t*)input, size);
+ tor_free(input);
+ return 0;
+}
+
+#endif
+