diff options
Diffstat (limited to 'src/fe-fuzz/irc/core')
-rw-r--r-- | src/fe-fuzz/irc/core/Makefile.am | 46 | ||||
-rw-r--r-- | src/fe-fuzz/irc/core/event-get-params.c | 82 |
2 files changed, 128 insertions, 0 deletions
diff --git a/src/fe-fuzz/irc/core/Makefile.am b/src/fe-fuzz/irc/core/Makefile.am new file mode 100644 index 00000000..fa614abb --- /dev/null +++ b/src/fe-fuzz/irc/core/Makefile.am @@ -0,0 +1,46 @@ +bin_PROGRAMS = event-get-params-fuzz + +# Force link with CXX for libfuzzer support +CCLD=$(CXX) $(CXXFLAGS) + +AM_CPPFLAGS = \ + -I$(top_srcdir)/src \ + -I$(top_srcdir)/src/core/ \ + -I$(top_srcdir)/src/irc/core/ \ + -I$(top_srcdir)/src/fe-common/core/ \ + $(GLIB_CFLAGS) + +AM_DEPENDENCIES = \ + ../../../core/libcore.a \ + ../../../lib-config/libirssi_config.a \ + ../../../irc/libirc.a \ + ../../../irc/core/libirc_core.a \ + ../../../irc/dcc/libirc_dcc.a \ + ../../../irc/flood/libirc_flood.a \ + ../../../irc/notifylist/libirc_notifylist.a \ + ../../../fe-common/core/libfe_common_core.a \ + ../../../fe-common/irc/libfe_common_irc.a \ + ../../../fe-common/irc/dcc/libfe_irc_dcc.a \ + ../../../fe-common/irc/notifylist/libfe_irc_notifylist a + +LDADD = \ + ../../../irc/libirc.a \ + ../../../irc/core/libirc_core.a \ + ../../../irc/dcc/libirc_dcc.a \ + ../../../irc/flood/libirc_flood.a \ + ../../../irc/notifylist/libirc_notifylist.a \ + ../../../fe-common/core/libfe_common_core.a \ + ../../../fe-common/irc/libfe_common_irc.a \ + ../../../fe-common/irc/dcc/libfe_irc_dcc.a \ + ../../../fe-common/irc/notifylist/libfe_irc_notifylist.a \ + ../../../core/libcore.a \ + ../../../lib-config/libirssi_config.a \ + @PROG_LIBS@ \ + $(FUZZER_LIBS) + +event_get_params_fuzz_SOURCES = \ + event-get-params.c \ + $(top_srcdir)/src/fe-text/module-formats.c + +noinst_HEADERS = \ + $(top_srcdir)/src/fe-text/module-formats.h diff --git a/src/fe-fuzz/irc/core/event-get-params.c b/src/fe-fuzz/irc/core/event-get-params.c new file mode 100644 index 00000000..c50b6205 --- /dev/null +++ b/src/fe-fuzz/irc/core/event-get-params.c @@ -0,0 +1,82 @@ +/* + event-get-params.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 "../fe-text/module-formats.h" // need to explicitly grab from fe-text +#include "themes.h" +#include "core.h" +#include "fe-common-core.h" +#include "args.h" +#include "printtext.h" +#include "irc.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"); + return 0; +} + +int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + if (size < 1) { + return 0; + } + uint8_t count = *data; + gchar *copy = g_strndup((const gchar *)data+1, size-1); + + char *output0; + char *output1; + char *output2; + char *output3; + char *params; + if (count % 8 == 0) { + params = event_get_params(copy, 1 | PARAM_FLAG_GETREST, &output0); + } else if (count % 8 == 1) { + params = event_get_params(copy, 2 | PARAM_FLAG_GETREST, &output0, &output1); + } else if (count % 8 == 2) { + params = event_get_params(copy, 3 | PARAM_FLAG_GETREST, &output0, &output1, &output2); + } else if (count % 8 == 3) { + params = event_get_params(copy, 4 | PARAM_FLAG_GETREST, &output0, &output1, &output2, &output3); + } else if (count % 8 == 4) { + params = event_get_params(copy, 1, &output0); + } else if (count % 8 == 5) { + params = event_get_params(copy, 2, &output0, &output1); + } else if (count % 8 == 6) { + params = event_get_params(copy, 3, &output0, &output1, &output2); + } else { + params = event_get_params(copy, 4, &output0, &output1, &output2, &output3); + } + g_free(params); + g_free(copy); + return 0; +} |