summaryrefslogtreecommitdiff
path: root/src/fe-fuzz/irssi.c
diff options
context:
space:
mode:
authorJoseph Bisch <joseph.bisch@gmail.com>2017-01-07 20:01:07 -0500
committerJoseph Bisch <joseph.bisch@gmail.com>2017-01-07 20:01:07 -0500
commitcf4690725667211bc8a8998e362c6bda24dd7528 (patch)
treeecd89755df29366a40806865a7910954a5b49e9f /src/fe-fuzz/irssi.c
parent7c09b72a26884bcd9711f39e2730ab09e658eec1 (diff)
downloadirssi-cf4690725667211bc8a8998e362c6bda24dd7528.zip
Add frontend for fuzzing
Use the following configure command: $ ./configure --with-fuzzer --with-fuzzer-lib=/path/to/libFuzzer.a \ CC=clang CXX=clang++ Places an irssi-fuzz in src/fe-fuzz/ after build. Also can specify SANFLAGS to override the chosen sanitizer flags (defaults to "-g -fsanitize=address -fsanitize-coverage=trace-pc-guard").
Diffstat (limited to 'src/fe-fuzz/irssi.c')
-rw-r--r--src/fe-fuzz/irssi.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/fe-fuzz/irssi.c b/src/fe-fuzz/irssi.c
new file mode 100644
index 00000000..3b2c617a
--- /dev/null
+++ b/src/fe-fuzz/irssi.c
@@ -0,0 +1,58 @@
+/*
+ irssi.c : irssi
+
+ Copyright (C) 2017 Joseph Bisch
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "module.h"
+#include "modules-load.h"
+#include "levels.h"
+#include "module-formats.h"
+#include "themes.h"
+#include "core.h"
+#include "fe-common-core.h"
+#include "args.h"
+#include "printtext.h"
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+int LLVMFuzzerInitialize(int *argc, char ***argv) {
+ core_register_options();
+ fe_common_core_register_options();
+ /* no args */
+ args_execute(0, NULL);
+ core_preinit((*argv)[0]);
+ core_init();
+ fe_common_core_init();
+ theme_register(gui_text_formats);
+ module_register("core", "fe-fuzz");
+ printtext_string(NULL, NULL, MSGLEVEL_CLIENTCRAP, "init");
+ return 0;
+}
+
+int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+ char *copy = (char *)malloc(sizeof(char)*(size+1));
+ memcpy(copy, data, size);
+ copy[size] = '\0';
+ printtext_string(NULL, NULL, MSGLEVEL_CLIENTCRAP, copy);
+ free(copy);
+ return 0;
+}