aboutsummaryrefslogtreecommitdiff
path: root/src/test/fuzz/fuzz_socks.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-07-12 14:20:46 -0400
committerNick Mathewson <nickm@torproject.org>2018-07-12 14:20:46 -0400
commit2d0e1cef20036412ed57c287553623293ab65031 (patch)
treec0cc010fa622dd5563b9342bcb046773c51dde78 /src/test/fuzz/fuzz_socks.c
parent7556933537b5777a9bef21230bb91a08aa70d60e (diff)
downloadtor-2d0e1cef20036412ed57c287553623293ab65031.tar.gz
tor-2d0e1cef20036412ed57c287553623293ab65031.zip
Add fuzzing wrapper for fetch_from_buf_socks()
Diffstat (limited to 'src/test/fuzz/fuzz_socks.c')
-rw-r--r--src/test/fuzz/fuzz_socks.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/test/fuzz/fuzz_socks.c b/src/test/fuzz/fuzz_socks.c
new file mode 100644
index 0000000000..14c25304b1
--- /dev/null
+++ b/src/test/fuzz/fuzz_socks.c
@@ -0,0 +1,50 @@
+/* Copyright (c) 2016-2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#include "orconfig.h"
+
+#define BUFFERS_PRIVATE
+#include "core/or/or.h"
+
+#include "lib/container/buffers.h"
+#include "lib/err/backtrace.h"
+#include "lib/log/log.h"
+#include "core/proto/proto_socks.h"
+#include "feature/client/addressmap.h"
+
+#include "test/fuzz/fuzzing.h"
+
+int
+fuzz_init(void)
+{
+ addressmap_init();
+ return 0;
+}
+
+int
+fuzz_cleanup(void)
+{
+ addressmap_free_all();
+ return 0;
+}
+
+int
+fuzz_main(const uint8_t *stdin_buf, size_t data_size)
+{
+ buf_t *buffer = buf_new_with_data((char*)stdin_buf, data_size);
+ if (!buffer) {
+ tor_assert(data_size==0);
+ buffer = buf_new();
+ }
+
+ socks_request_t *request = socks_request_new();
+
+ int r = fetch_from_buf_socks(buffer, request, 0, 0);
+ log_info(LD_GENERAL, "Socks request status: %d", r);
+
+ /* Reset. */
+ buf_free(buffer);
+ socks_request_free(request);
+
+ return 0;
+}