aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/fuzz/setconf.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-01-11 16:28:19 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-01-11 10:47:59 -0500
commit95c30bc0344b4e3085336c5b957ea1d1281b0d0b (patch)
treeb8df0aa2b54e782125ef6ee4d76599f527b6f318 /src/fuzz/setconf.c
parentMakefile: evaluate git version lazily (diff)
downloadwireguard-tools-95c30bc0344b4e3085336c5b957ea1d1281b0d0b.tar.xz
wireguard-tools-95c30bc0344b4e3085336c5b957ea1d1281b0d0b.zip
fuzz: add set and setconf fuzzers
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--src/fuzz/setconf.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/fuzz/setconf.c b/src/fuzz/setconf.c
new file mode 100644
index 0000000..44bfeb9
--- /dev/null
+++ b/src/fuzz/setconf.c
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2018-2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
+ */
+
+#include <stdio.h>
+#undef stderr
+#define stderr stdin
+#define RUNSTATEDIR "/var/empty"
+#include "../curve25519.c"
+#define parse_allowedips parse_allowedips_ipc
+#include "../ipc.c"
+#undef parse_allowedips
+#include "../encoding.c"
+#include "../config.c"
+#include "../mnlg.c"
+static FILE *hacked_fopen(const char *pathname, const char *mode);
+#define fopen hacked_fopen
+#include "../setconf.c"
+#undef fopen
+#undef stderr
+
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+
+const char *__asan_default_options()
+{
+ return "verbosity=1";
+}
+
+const char *PROG_NAME = "wg";
+
+struct hacked_pointers {
+ const char *data;
+ size_t data_len;
+};
+
+static FILE *hacked_fopen(const char *pathname, const char *mode)
+{
+ struct hacked_pointers *h = (struct hacked_pointers *)strtoul(pathname, NULL, 10);
+ return fmemopen((char *)h->data, h->data_len, "r");
+}
+
+int LLVMFuzzerTestOneInput(const char *data, size_t data_len)
+{
+ char strptr[32];
+ char *argv[3] = { "setconf", "wg0", strptr };
+ struct hacked_pointers h = { data, data_len };
+
+ snprintf(strptr, sizeof(strptr), "%lu", (unsigned long)&h);
+ setconf_main(3, argv);
+ return 0;
+}