diff options
author | Nick Mathewson <nickm@torproject.org> | 2016-12-13 19:41:03 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2016-12-19 15:34:56 -0500 |
commit | 60769e710f1099168f7508fe6834e458ce435ad9 (patch) | |
tree | ade0966556fa037e6440766f976572c899405269 /src/test/fuzz/fuzzing_common.c | |
parent | a967d568dcab10d6b1e03d2ffb96743e415393c0 (diff) | |
download | tor-60769e710f1099168f7508fe6834e458ce435ad9.tar.gz tor-60769e710f1099168f7508fe6834e458ce435ad9.zip |
Port fuzz_http to use fuzzing_common.
Move common logic from fuzz_http to fuzzing_common.
Diffstat (limited to 'src/test/fuzz/fuzzing_common.c')
-rw-r--r-- | src/test/fuzz/fuzzing_common.c | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/src/test/fuzz/fuzzing_common.c b/src/test/fuzz/fuzzing_common.c index 51d519b861..87affc4c04 100644 --- a/src/test/fuzz/fuzzing_common.c +++ b/src/test/fuzz/fuzzing_common.c @@ -1,8 +1,7 @@ #include "orconfig.h" -#include "torint.h" -#include "util.h" -#include "torlog.h" +#include "or.h" #include "backtrace.h" +#include "config.h" #include "fuzzing.h" extern const char tor_git_revision[]; @@ -28,23 +27,56 @@ 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); + /* Disable logging by default to speed up fuzzing. */ + int loglevel = LOG_ERR; + + /* Initialise logging first */ + init_logging(1); + configure_backtrace_handler(get_version()); + + for (int i = 1; i < argc; ++i) { + if (!strcmp(argv[i], "--warn")) { + loglevel = LOG_WARN; + } else if (!strcmp(argv[i], "--notice")) { + loglevel = LOG_NOTICE; + } else if (!strcmp(argv[i], "--info")) { + loglevel = LOG_INFO; + } else if (!strcmp(argv[i], "--debug")) { + loglevel = LOG_DEBUG; + } } - tor_assert(input); + { + log_severity_list_t s; + memset(&s, 0, sizeof(s)); + set_log_severity_config(loglevel, LOG_ERR, &s); + /* ALWAYS log bug warnings. */ + s.masks[LOG_WARN-LOG_ERR] |= LD_BUG; + add_stream_log(&s, "", fileno(stdout)); + } + + /* Make BUG() and nonfatal asserts crash */ + tor_set_failed_assertion_callback(abort); + if (fuzz_init() < 0) abort(); + +#ifdef __AFL_HAVE_MANUAL_CONTROL + /* Tell AFL to pause and fork here - ignored if not using AFL */ + __AFL_INIT(); +#endif + + char *input = read_file_to_str_until_eof(0, MAX_FUZZ_SIZE, &size); + tor_assert(input); fuzz_main((const uint8_t*)input, size); tor_free(input); + + if (fuzz_cleanup() < 0) + abort(); return 0; } |