diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 6 | ||||
-rw-r--r-- | src/fe-common/core/hilight-text.c | 15 | ||||
-rw-r--r-- | src/fe-common/core/printtext.c | 2 | ||||
-rw-r--r-- | src/fe-fuzz/Makefile.am | 25 | ||||
-rw-r--r-- | src/fe-fuzz/irssi.c | 57 | ||||
-rw-r--r-- | src/fe-fuzz/tokens.txt | 143 | ||||
-rw-r--r-- | src/fe-text/gui-windows.c | 10 | ||||
-rw-r--r-- | src/fe-text/textbuffer-view.c | 15 | ||||
-rw-r--r-- | src/fe-text/textbuffer-view.h | 3 | ||||
-rw-r--r-- | src/fe-text/textbuffer.c | 8 | ||||
-rw-r--r-- | src/fe-text/textbuffer.h | 1 |
11 files changed, 270 insertions, 15 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 76a4af4f..a7fb2ee2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,6 +6,10 @@ if BUILD_IRSSIBOT BOTUI=fe-none endif +if BUILD_IRSSIFUZZER +FUZZERUI=fe-fuzz +endif + if HAVE_PERL PERLDIR=perl endif @@ -14,4 +18,4 @@ pkginc_srcdir=$(pkgincludedir)/src pkginc_src_HEADERS = \ common.h -SUBDIRS = lib-config core irc fe-common $(PERLDIR) $(TEXTUI) $(BOTUI) +SUBDIRS = lib-config core irc fe-common $(PERLDIR) $(TEXTUI) $(BOTUI) $(FUZZERUI) diff --git a/src/fe-common/core/hilight-text.c b/src/fe-common/core/hilight-text.c index 037cde5c..dd38be87 100644 --- a/src/fe-common/core/hilight-text.c +++ b/src/fe-common/core/hilight-text.c @@ -399,34 +399,29 @@ static void sig_print_text(TEXT_DEST_REC *dest, const char *text, char *middle; int pos, color_pos, color_len; - tmp = g_string_new(NULL); - /* start of the line */ pos = strip_real_length(text, hilight_start, NULL, NULL); - g_string_append(tmp, text); - g_string_truncate(tmp, pos); + tmp = g_string_new_len(text, pos); /* color */ g_string_append(tmp, color); /* middle of the line, stripped */ - middle = strip_codes(text+pos); - pos = tmp->len; - g_string_append(tmp, middle); - g_string_truncate(tmp, pos+hilight_len); + middle = strip_codes(text + pos); + g_string_append_len(tmp, middle, hilight_len); g_free(middle); /* end of the line */ pos = strip_real_length(text, hilight_end, &color_pos, &color_len); if (color_pos > 0) - g_string_append_len(tmp, text+color_pos, color_len); + g_string_append_len(tmp, text + color_pos, color_len); else { /* no colors in line, change back to default */ g_string_append_c(tmp, 4); g_string_append_c(tmp, FORMAT_STYLE_DEFAULTS); } - g_string_append(tmp, text+pos); + g_string_append(tmp, text + pos); newstr = tmp->str; g_string_free(tmp, FALSE); diff --git a/src/fe-common/core/printtext.c b/src/fe-common/core/printtext.c index ba6f3242..01ef2dcd 100644 --- a/src/fe-common/core/printtext.c +++ b/src/fe-common/core/printtext.c @@ -446,7 +446,9 @@ static void sig_print_text(TEXT_DEST_REC *dest, const char *text) if (dest->window == NULL) { str = strip_codes(text); +#ifndef SUPPRESS_PRINTF_FALLBACK printf("NO WINDOWS: %s\n", str); +#endif g_free(str); return; } diff --git a/src/fe-fuzz/Makefile.am b/src/fe-fuzz/Makefile.am new file mode 100644 index 00000000..3a547c66 --- /dev/null +++ b/src/fe-fuzz/Makefile.am @@ -0,0 +1,25 @@ +bin_PROGRAMS = irssi-fuzz + +# Force link with clang++ for libfuzzer support +CCLD=clang++ $(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) + +irssi_fuzz_DEPENDENCIES = @COMMON_LIBS@ + +irssi_fuzz_LDADD = \ + @COMMON_LIBS@ \ + @PROG_LIBS@ \ + $(FUZZER_LIBS) + +irssi_fuzz_SOURCES = \ + irssi.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/irssi.c b/src/fe-fuzz/irssi.c new file mode 100644 index 00000000..77892aaf --- /dev/null +++ b/src/fe-fuzz/irssi.c @@ -0,0 +1,57 @@ +/* + 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 "../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 <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; +} diff --git a/src/fe-fuzz/tokens.txt b/src/fe-fuzz/tokens.txt new file mode 100644 index 00000000..e337b6e9 --- /dev/null +++ b/src/fe-fuzz/tokens.txt @@ -0,0 +1,143 @@ +"@%+" +"*@*!*" +"001" +"002" +"003" +"004" +"005" +"221" +"254" +"271" +"272" +"281" +"301" +"302" +"303" +"305" +"306" +"311" +"312" +"313" +"314" +"315" +"317" +"318" +"319" +"324" +"326" +"327" +"328" +"329" +"330" +"332" +"333" +"338" +"341" +"344" +"345" +"346" +"347" +"348" +"349" +"352" +"353" +"364" +"365" +"366" +"367" +"368" +"369" +"372" +"375" +"376" +"377" +"378" +"379" +"381" +"386" +"387" +"388" +"389" +"396" +"401" +"403" +"404" +"405" +"407" +"408" +"410" +"421" +"422" +"433" +"436" +"437" +"438" +"439" +"442" +"465" +"470" +"471" +"472" +"473" +"474" +"475" +"476" +"477" +"478" +"479" +"482" +"486" +"489" +"494" +"506" +"707" +"716" +"717" +"728" +"729" +"902" +"903" +"904" +"905" +"906" +"907" +":a" +"+a" +"ACK" +"authenticate" +"away" +"-b" +"+b" +"cap" +"#chan" +"connected" +"empty" +"error" +"invite" +"join" +"kick" +"kill" +"LS" +"mode" +"multi-prefix" +"NAK" +"network" +"nick" +"nicklen" +"notice" +"-o" +"+o" +"part" +"ping" +"pong" +"prefix" +"privmsg" +"quit" +"sasl" +"topic" +"wallops" +"watch" +":\x01" +":\x01ACTION" +":\x01PING" +":\x01VERSION" diff --git a/src/fe-text/gui-windows.c b/src/fe-text/gui-windows.c index 4213149d..c63c495c 100644 --- a/src/fe-text/gui-windows.c +++ b/src/fe-text/gui-windows.c @@ -49,6 +49,7 @@ static GUI_WINDOW_REC *gui_window_init(WINDOW_REC *window, settings_get_int("indent"), !settings_get_bool("indent_always"), get_default_indent_func()); + textbuffer_view_set_break_wide(gui->view, settings_get_bool("break_wide")); if (parent->active == window) textbuffer_view_set_window(gui->view, parent->screen_win); return gui; @@ -201,12 +202,14 @@ void gui_windows_reset_settings(void) for (tmp = windows; tmp != NULL; tmp = tmp->next) { WINDOW_REC *rec = tmp->data; - GUI_WINDOW_REC *gui = WINDOW_GUI(rec); + GUI_WINDOW_REC *gui = WINDOW_GUI(rec); - textbuffer_view_set_default_indent(gui->view, + textbuffer_view_set_break_wide(gui->view, settings_get_bool("break_wide")); + + textbuffer_view_set_default_indent(gui->view, settings_get_int("indent"), !settings_get_bool("indent_always"), - get_default_indent_func()); + get_default_indent_func()); textbuffer_view_set_scroll(gui->view, gui->use_scroll ? gui->scroll : @@ -281,6 +284,7 @@ void gui_windows_init(void) settings_add_bool("lookandfeel", "autostick_split_windows", TRUE); settings_add_int("lookandfeel", "indent", 10); settings_add_bool("lookandfeel", "indent_always", FALSE); + settings_add_bool("lookandfeel", "break_wide", FALSE); settings_add_bool("lookandfeel", "scroll", TRUE); window_create_override = -1; diff --git a/src/fe-text/textbuffer-view.c b/src/fe-text/textbuffer-view.c index e2e3707b..58bd36fb 100644 --- a/src/fe-text/textbuffer-view.c +++ b/src/fe-text/textbuffer-view.c @@ -146,6 +146,9 @@ static void update_cmd_color(unsigned char cmd, int *color) case LINE_CMD_ITALIC: *color ^= ATTR_ITALIC; break; + case LINE_CMD_MONOSPACE: + /* ignored */ + break; case LINE_CMD_COLOR0: *color &= BGATTR; *color &= ~ATTR_FGCOLOR24; @@ -307,7 +310,7 @@ view_update_line_cache(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line) continue; } - if (!view->utf8 && char_width > 1) { + if (view->break_wide && char_width > 1) { last_space = xpos; last_space_ptr = next_ptr; last_color = color; last_fg24 = fg24; last_bg24 = bg24; @@ -665,6 +668,16 @@ void textbuffer_view_set_default_indent(TEXT_BUFFER_VIEW_REC *view, view->default_indent_func = indent_func; } +/* Enable breaking of wide chars */ +void textbuffer_view_set_break_wide(TEXT_BUFFER_VIEW_REC *view, + gboolean break_wide) +{ + if (view->break_wide != break_wide) { + view->break_wide = break_wide; + view_reset_cache(view); + } +} + static void view_unregister_indent_func(TEXT_BUFFER_VIEW_REC *view, INDENT_FUNC indent_func) { diff --git a/src/fe-text/textbuffer-view.h b/src/fe-text/textbuffer-view.h index 21a9bde6..5e7a9d0a 100644 --- a/src/fe-text/textbuffer-view.h +++ b/src/fe-text/textbuffer-view.h @@ -59,6 +59,7 @@ struct _TEXT_BUFFER_VIEW_REC { unsigned int longword_noindent:1; unsigned int scroll:1; /* scroll down automatically when at bottom */ unsigned int utf8:1; /* use UTF8 in this view */ + unsigned int break_wide:1; /* Break wide chars in this view */ TEXT_BUFFER_CACHE_REC *cache; int ypos; /* cursor position - visible area is 0..height-1 */ @@ -97,6 +98,8 @@ void textbuffer_view_set_default_indent(TEXT_BUFFER_VIEW_REC *view, int longword_noindent, INDENT_FUNC indent_func); void textbuffer_views_unregister_indent_func(INDENT_FUNC indent_func); +void textbuffer_view_set_break_wide(TEXT_BUFFER_VIEW_REC *view, + gboolean break_wide); void textbuffer_view_set_scroll(TEXT_BUFFER_VIEW_REC *view, int scroll); void textbuffer_view_set_utf8(TEXT_BUFFER_VIEW_REC *view, int utf8); diff --git a/src/fe-text/textbuffer.c b/src/fe-text/textbuffer.c index ae4636a5..3668f4c7 100644 --- a/src/fe-text/textbuffer.c +++ b/src/fe-text/textbuffer.c @@ -326,6 +326,10 @@ void textbuffer_line_add_colors(TEXT_BUFFER_REC *buffer, LINE_REC **line, data[pos++] = 0; data[pos++] = LINE_CMD_ITALIC; } + if ((flags & GUI_PRINT_FLAG_MONOSPACE) != (buffer->last_flags & GUI_PRINT_FLAG_MONOSPACE)) { + data[pos++] = 0; + data[pos++] = LINE_CMD_MONOSPACE; + } if (flags & GUI_PRINT_FLAG_INDENT) { data[pos++] = 0; data[pos++] = LINE_CMD_INDENT; @@ -509,6 +513,10 @@ void textbuffer_line2text(LINE_REC *line, int coloring, GString *str) g_string_append_printf(str, "\004%c", FORMAT_STYLE_ITALIC); break; + case LINE_CMD_MONOSPACE: + g_string_append_printf(str, "\004%c", + FORMAT_STYLE_MONOSPACE); + break; case LINE_CMD_COLOR0: g_string_append_printf(str, "\004%c%c", '0', FORMAT_COLOR_NOCHANGE); diff --git a/src/fe-text/textbuffer.h b/src/fe-text/textbuffer.h index eacfd447..303789a3 100644 --- a/src/fe-text/textbuffer.h +++ b/src/fe-text/textbuffer.h @@ -18,6 +18,7 @@ enum { LINE_CMD_BLINK, /* enable/disable blink */ LINE_CMD_BOLD, /* enable/disable bold */ LINE_CMD_ITALIC, /* enable/disable italic */ + LINE_CMD_MONOSPACE, /* enable/disable monospace (gui only) */ LINE_COLOR_EXT, /* extended color */ LINE_COLOR_EXT_BG, /* extended bg */ #ifdef TERM_TRUECOLOR |