diff options
-rw-r--r-- | AUTHORS | 2 | ||||
-rw-r--r-- | configure.ac | 18 | ||||
-rw-r--r-- | src/common.h | 2 | ||||
-rw-r--r-- | src/core/ignore.c | 28 | ||||
-rw-r--r-- | src/core/ignore.h | 6 | ||||
-rw-r--r-- | src/core/misc.c | 2 | ||||
-rw-r--r-- | src/fe-common/core/fe-ignore.c | 5 | ||||
-rw-r--r-- | src/fe-common/core/hilight-text.c | 41 | ||||
-rw-r--r-- | src/fe-common/core/hilight-text.h | 6 | ||||
-rw-r--r-- | src/fe-common/irc/fe-irc-queries.c | 7 | ||||
-rw-r--r-- | src/fe-common/irc/fe-sasl.c | 29 | ||||
-rw-r--r-- | src/fe-text/gui-printtext.c | 3 | ||||
-rw-r--r-- | src/fe-text/statusbar-config.c | 2 | ||||
-rw-r--r-- | src/fe-text/textbuffer.c | 40 | ||||
-rw-r--r-- | src/irc/core/irc-queries.c | 16 | ||||
-rw-r--r-- | src/irc/core/irc-servers.h | 1 | ||||
-rw-r--r-- | src/irc/core/sasl.c | 7 | ||||
-rw-r--r-- | src/perl/irc/Irc.xs | 1 |
18 files changed, 163 insertions, 53 deletions
@@ -13,6 +13,7 @@ Irssi staff (current maintainers) <staff@irssi.org>: Jase Thew (bazerka) dequis (dx) Ailin Nemui (Nei) + Giuseppe (TheLemonMan, lemonboy) Former developers: @@ -26,7 +27,6 @@ Large feature patches by: Heikki Orsila : DCC SEND queueing Mark Trumbull : DCC SERVER Francesco Fracassi : Passive DCC - Giuseppe (The Lemon Man) Other patches (grep for "patch" in ChangeLog) by: diff --git a/configure.ac b/configure.ac index 464f6288..53d65671 100644 --- a/configure.ac +++ b/configure.ac @@ -21,7 +21,7 @@ AC_PATH_PROG(perlpath, perl) AC_CHECK_HEADERS(unistd.h dirent.h sys/ioctl.h sys/resource.h) # check posix headers.. -AC_CHECK_HEADERS(sys/socket.h sys/time.h sys/utsname.h regex.h) +AC_CHECK_HEADERS(sys/socket.h sys/time.h sys/utsname.h) AC_SYS_LARGEFILE @@ -144,6 +144,15 @@ AC_ARG_ENABLE(true-color, fi, want_truecolor=no) +AC_ARG_ENABLE(gregex, +[ --disable-gregex Build without GRegex (fall back to regex.h)], + if test x$enableval = xno ; then + want_gregex=no + else + want_gregex=yes + fi, + want_gregex=yes) + dnl ** dnl ** just some generic stuff... dnl ** @@ -534,6 +543,12 @@ else want_truecolor=no fi +if test "x$want_gregex" = "xyes"; then + AC_DEFINE([USE_GREGEX], [], [use GRegex for regular expressions]) +else + want_gregex=no +fi + AH_TEMPLATE(HAVE_GMODULE) AH_TEMPLATE(HAVE_SOCKS_H, [misc..]) AH_TEMPLATE(HAVE_STATIC_PERL) @@ -648,6 +663,7 @@ echo echo "Building with 64bit DCC support .. : $offt_64bit" echo "Building with true color support.. : $want_truecolor" +echo "Building with GRegex ............. : $want_gregex" echo echo "If there are any problems, read the INSTALL file." diff --git a/src/common.h b/src/common.h index 0a7b72f0..43596580 100644 --- a/src/common.h +++ b/src/common.h @@ -6,7 +6,7 @@ #define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */ #define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */ -#define IRSSI_ABI_VERSION 6 +#define IRSSI_ABI_VERSION 7 #define DEFAULT_SERVER_ADD_PORT 6667 diff --git a/src/core/ignore.c b/src/core/ignore.c index 2047dc9d..bf8db04f 100644 --- a/src/core/ignore.c +++ b/src/core/ignore.c @@ -67,11 +67,12 @@ static int ignore_match_pattern(IGNORE_REC *rec, const char *text) return FALSE; if (rec->regexp) { -#ifdef HAVE_REGEX_H +#ifdef USE_GREGEX + return rec->preg != NULL && + g_regex_match(rec->preg, text, 0, NULL); +#else return rec->regexp_compiled && regexec(&rec->preg, text, 0, NULL, 0) == 0; -#else - return FALSE; #endif } @@ -326,12 +327,27 @@ static void ignore_remove_config(IGNORE_REC *rec) static void ignore_init_rec(IGNORE_REC *rec) { -#ifdef HAVE_REGEX_H +#ifdef USE_GREGEX + if (rec->preg != NULL) + g_regex_unref(rec->preg); + + if (rec->regexp && rec->pattern != NULL) { + GError *re_error; + + rec->preg = g_regex_new(rec->pattern, G_REGEX_OPTIMIZE | G_REGEX_RAW | G_REGEX_CASELESS, 0, &re_error); + + if (rec->preg == NULL) { + g_warning("Failed to compile regexp '%s': %s", rec->pattern, re_error->message); + g_error_free(re_error); + } + } +#else char *errbuf; int errcode, errbuf_len; if (rec->regexp_compiled) regfree(&rec->preg); rec->regexp_compiled = FALSE; + if (rec->regexp && rec->pattern != NULL) { errcode = regcomp(&rec->preg, rec->pattern, REG_EXTENDED|REG_ICASE|REG_NOSUB); @@ -365,7 +381,9 @@ static void ignore_destroy(IGNORE_REC *rec, int send_signal) if (send_signal) signal_emit("ignore destroyed", 1, rec); -#ifdef HAVE_REGEX_H +#ifdef USE_GREGEX + if (rec->preg != NULL) g_regex_unref(rec->preg); +#else if (rec->regexp_compiled) regfree(&rec->preg); #endif if (rec->channels != NULL) g_strfreev(rec->channels); diff --git a/src/core/ignore.h b/src/core/ignore.h index f889740f..80ae1d12 100644 --- a/src/core/ignore.h +++ b/src/core/ignore.h @@ -1,7 +1,7 @@ #ifndef __IGNORE_H #define __IGNORE_H -#ifdef HAVE_REGEX_H +#ifndef USE_GREGEX # include <regex.h> #endif @@ -20,7 +20,9 @@ struct _IGNORE_REC { unsigned int regexp:1; unsigned int fullword:1; unsigned int replies:1; /* ignore replies to nick in channel */ -#ifdef HAVE_REGEX_H +#ifdef USE_GREGEX + GRegex *preg; +#else unsigned int regexp_compiled:1; /* should always be TRUE, unless regexp is invalid */ regex_t preg; #endif diff --git a/src/core/misc.c b/src/core/misc.c index 0bb1f7e6..1cfa15b6 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -22,7 +22,7 @@ #include "misc.h" #include "commands.h" -#ifdef HAVE_REGEX_H +#ifndef USE_GREGEX # include <regex.h> #endif diff --git a/src/fe-common/core/fe-ignore.c b/src/fe-common/core/fe-ignore.c index 52b11e6b..800e881d 100644 --- a/src/fe-common/core/fe-ignore.c +++ b/src/fe-common/core/fe-ignore.c @@ -58,7 +58,10 @@ static void ignore_print(int index, IGNORE_REC *rec) g_string_append(options, "-regexp "); if (rec->pattern == NULL) g_string_append(options, "[INVALID! -pattern missing] "); -#ifdef HAVE_REGEX_H +#ifdef USE_GREGEX + else if (rec->preg == NULL) + g_string_append(options, "[INVALID!] "); +#else else if (!rec->regexp_compiled) g_string_append(options, "[INVALID!] "); #endif diff --git a/src/fe-common/core/hilight-text.c b/src/fe-common/core/hilight-text.c index 4691a708..037cde5c 100644 --- a/src/fe-common/core/hilight-text.c +++ b/src/fe-common/core/hilight-text.c @@ -101,7 +101,9 @@ static void hilight_destroy(HILIGHT_REC *rec) { g_return_if_fail(rec != NULL); -#ifdef HAVE_REGEX_H +#ifdef USE_GREGEX + if (rec->preg != NULL) g_regex_unref(rec->preg); +#else if (rec->regexp_compiled) regfree(&rec->preg); #endif if (rec->channels != NULL) g_strfreev(rec->channels); @@ -120,7 +122,12 @@ static void hilights_destroy_all(void) static void hilight_init_rec(HILIGHT_REC *rec) { -#ifdef HAVE_REGEX_H +#ifdef USE_GREGEX + if (rec->preg != NULL) + g_regex_unref(rec->preg); + + rec->preg = g_regex_new(rec->text, G_REGEX_OPTIMIZE | G_REGEX_RAW | G_REGEX_CASELESS, 0, NULL); +#else if (rec->regexp_compiled) regfree(&rec->preg); if (!rec->regexp) rec->regexp_compiled = FALSE; @@ -194,13 +201,24 @@ static HILIGHT_REC *hilight_find(const char *text, char **channels) return NULL; } -static int hilight_match_text(HILIGHT_REC *rec, const char *text, +static gboolean hilight_match_text(HILIGHT_REC *rec, const char *text, int *match_beg, int *match_end) { - char *match; + gboolean ret = FALSE; if (rec->regexp) { -#ifdef HAVE_REGEX_H +#ifdef USE_GREGEX + if (rec->preg != NULL) { + GMatchInfo *match; + + g_regex_match (rec->preg, text, 0, &match); + + if (g_match_info_matches(match)) + ret = g_match_info_fetch_pos(match, 0, match_beg, match_end); + + g_match_info_free(match); + } +#else regmatch_t rmatch[1]; if (rec->regexp_compiled && @@ -210,10 +228,12 @@ static int hilight_match_text(HILIGHT_REC *rec, const char *text, *match_beg = rmatch[0].rm_so; *match_end = rmatch[0].rm_eo; } - return TRUE; + ret = TRUE; } #endif } else { + char *match; + if (rec->case_sensitive) { match = rec->fullword ? strstr_full(text, rec->text) : @@ -228,11 +248,11 @@ static int hilight_match_text(HILIGHT_REC *rec, const char *text, *match_beg = (int) (match-text); *match_end = *match_beg + strlen(rec->text); } - return TRUE; + ret = TRUE; } } - return FALSE; + return ret; } #define hilight_match_level(rec, level) \ @@ -509,7 +529,10 @@ static void hilight_print(int index, HILIGHT_REC *rec) if (rec->case_sensitive) g_string_append(options, "-matchcase "); if (rec->regexp) { g_string_append(options, "-regexp "); -#ifdef HAVE_REGEX_H +#ifdef USE_GREGEX + if (rec->preg == NULL) + g_string_append(options, "[INVALID!] "); +#else if (!rec->regexp_compiled) g_string_append(options, "[INVALID!] "); #endif diff --git a/src/fe-common/core/hilight-text.h b/src/fe-common/core/hilight-text.h index ae05e1ca..76beec1f 100644 --- a/src/fe-common/core/hilight-text.h +++ b/src/fe-common/core/hilight-text.h @@ -1,7 +1,7 @@ #ifndef __HILIGHT_TEXT_H #define __HILIGHT_TEXT_H -#ifdef HAVE_REGEX_H +#ifndef USE_GREGEX # include <regex.h> #endif @@ -24,7 +24,9 @@ struct _HILIGHT_REC { unsigned int fullword:1; /* match `text' only for full words */ unsigned int regexp:1; /* `text' is a regular expression */ unsigned int case_sensitive:1;/* `text' must match case */ -#ifdef HAVE_REGEX_H +#ifdef USE_GREGEX + GRegex *preg; +#else unsigned int regexp_compiled:1; /* should always be TRUE, unless regexp is invalid */ regex_t preg; #endif diff --git a/src/fe-common/irc/fe-irc-queries.c b/src/fe-common/irc/fe-irc-queries.c index b2faefbc..c928a94a 100644 --- a/src/fe-common/irc/fe-irc-queries.c +++ b/src/fe-common/irc/fe-irc-queries.c @@ -78,6 +78,13 @@ static void event_privmsg(SERVER_REC *server, const char *data, if (!server_has_nick(server, query->name)) query_change_nick(query, nick); } + } else { + /* process the changes to the query structure now, before the + * privmsg is dispatched. */ + if (g_strcmp0(query->name, nick) != 0) + query_change_nick(query, nick); + if (address != NULL && g_strcmp0(query->address, address) != 0) + query_change_address(query, address); } } diff --git a/src/fe-common/irc/fe-sasl.c b/src/fe-common/irc/fe-sasl.c index 331b38b0..fc8105fc 100644 --- a/src/fe-common/irc/fe-sasl.c +++ b/src/fe-common/irc/fe-sasl.c @@ -1,7 +1,7 @@ /* fe-sasl.c : irssi - Copyright (C) 2015 The Lemon Man + Copyright (C) 2015-2017 The Lemon Man 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 @@ -22,6 +22,11 @@ #include "module-formats.h" #include "signals.h" #include "levels.h" +#include "misc.h" +#include "sasl.h" + +#include "irc-servers.h" +#include "settings.h" #include "printtext.h" @@ -35,14 +40,36 @@ static void sig_sasl_failure(IRC_SERVER_REC *server, const char *reason) printformat(server, NULL, MSGLEVEL_CRAP, IRCTXT_SASL_ERROR, reason); } +static void sig_cap_end(IRC_SERVER_REC *server) +{ + /* The negotiation has now been terminated, if we didn't manage to + * authenticate successfully with the server just disconnect. */ + if (!server->sasl_success && + server->connrec->sasl_mechanism != SASL_MECHANISM_NONE && + settings_get_bool("sasl_disconnect_on_failure")) { + /* We can't use server_disconnect() here because we'd end up + * freeing the 'server' object and be guilty of a slew of UaF. */ + server->connection_lost = TRUE; + /* By setting connection_lost we make sure the communication is + * halted and when the control goes back to irc_parse_incoming + * the server object is safely destroyed. */ + signal_stop(); + } + +} + void fe_sasl_init(void) { + settings_add_bool("server", "sasl_disconnect_on_failure", TRUE); + signal_add("server sasl success", (SIGNAL_FUNC) sig_sasl_success); signal_add("server sasl failure", (SIGNAL_FUNC) sig_sasl_failure); + signal_add_first("server cap end", (SIGNAL_FUNC) sig_cap_end); } void fe_sasl_deinit(void) { signal_remove("server sasl success", (SIGNAL_FUNC) sig_sasl_success); signal_remove("server sasl failure", (SIGNAL_FUNC) sig_sasl_failure); + signal_remove("server cap end", (SIGNAL_FUNC) sig_cap_end); } diff --git a/src/fe-text/gui-printtext.c b/src/fe-text/gui-printtext.c index 775e6044..a07451fa 100644 --- a/src/fe-text/gui-printtext.c +++ b/src/fe-text/gui-printtext.c @@ -169,7 +169,8 @@ static void get_colors(int flags, int *fg, int *bg, int *attr) if (*bg >= 0) { *bg = mirc_colors[*bg % 100]; flags &= ~GUI_PRINT_FLAG_COLOR_24_BG; - if (settings_get_bool("mirc_blink_fix")) { + /* ignore mirc color 99 = -1 (reset) */ + if (*bg != -1 && settings_get_bool("mirc_blink_fix")) { if (*bg < 16) /* ansi bit flip :-( */ *bg = (*bg&8) | (*bg&4)>>2 | (*bg&2) | (*bg&1)<<2; *bg = term_color256map[*bg&0xff] & 7; diff --git a/src/fe-text/statusbar-config.c b/src/fe-text/statusbar-config.c index a47a709e..48f4aa61 100644 --- a/src/fe-text/statusbar-config.c +++ b/src/fe-text/statusbar-config.c @@ -194,6 +194,8 @@ static void statusbar_read_group(CONFIG_NODE *node) STATUSBAR_GROUP_REC *group; GSList *tmp; + g_return_if_fail(is_node_list(node)); + group = statusbar_group_find(node->key); if (group == NULL) { group = statusbar_group_create(node->key); diff --git a/src/fe-text/textbuffer.c b/src/fe-text/textbuffer.c index 24ee62bc..ae4636a5 100644 --- a/src/fe-text/textbuffer.c +++ b/src/fe-text/textbuffer.c @@ -27,7 +27,7 @@ #include "textbuffer.h" -#ifdef HAVE_REGEX_H +#ifndef USE_GREGEX # include <regex.h> #endif @@ -537,7 +537,9 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline, int before, int after, int regexp, int fullword, int case_sensitive) { -#ifdef HAVE_REGEX_H +#ifdef USE_GREGEX + GRegex *preg; +#else regex_t preg; #endif LINE_REC *line, *pre_line; @@ -549,16 +551,23 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline, g_return_val_if_fail(buffer != NULL, NULL); g_return_val_if_fail(text != NULL, NULL); +#ifdef USE_GREGEX + preg = NULL; + + if (regexp) { + preg = g_regex_new(text, G_REGEX_RAW | (case_sensitive ? 0 : G_REGEX_CASELESS), 0, NULL); + + if (preg == NULL) + return NULL; + } +#else if (regexp) { -#ifdef HAVE_REGEX_H int flags = REG_EXTENDED | REG_NOSUB | (case_sensitive ? 0 : REG_ICASE); if (regcomp(&preg, text, flags) != 0) return NULL; -#else - return NULL; -#endif } +#endif matches = NULL; match_after = 0; str = g_string_new(NULL); @@ -577,12 +586,15 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline, if (*text != '\0') { textbuffer_line2text(line, FALSE, str); - if (line_matched) - line_matched = -#ifdef HAVE_REGEX_H - regexp ? regexec(&preg, str->str, 0, NULL, 0) == 0 : + if (line_matched) { + line_matched = regexp ? +#ifdef USE_GREGEX + g_regex_match(preg, str->str, 0, NULL) +#else + regexec(&preg, str->str, 0, NULL, 0) == 0 #endif - match_func(str->str, text) != NULL; + : match_func(str->str, text) != NULL; + } } if (line_matched) { @@ -610,7 +622,11 @@ GList *textbuffer_find_text(TEXT_BUFFER_REC *buffer, LINE_REC *startline, matches = g_list_append(matches, NULL); } } -#ifdef HAVE_REGEX_H + +#ifdef USE_GREGEX + if (preg != NULL) + g_regex_unref(preg); +#else if (regexp) regfree(&preg); #endif g_string_free(str, TRUE); diff --git a/src/irc/core/irc-queries.c b/src/irc/core/irc-queries.c index 12861744..b611e621 100644 --- a/src/irc/core/irc-queries.c +++ b/src/irc/core/irc-queries.c @@ -79,20 +79,6 @@ static void check_query_changes(IRC_SERVER_REC *server, const char *nick, } } -static void event_privmsg(IRC_SERVER_REC *server, const char *data, - const char *nick, const char *address) -{ - char *params, *target, *msg; - - g_return_if_fail(data != NULL); - if (nick == NULL) - return; - - params = event_get_params(data, 2 | PARAM_FLAG_GETREST, &target, &msg); - check_query_changes(server, nick, address, target); - g_free(params); -} - static void ctcp_action(IRC_SERVER_REC *server, const char *msg, const char *nick, const char *address, const char *target) @@ -117,14 +103,12 @@ static void event_nick(SERVER_REC *server, const char *data, void irc_queries_init(void) { - signal_add_last("event privmsg", (SIGNAL_FUNC) event_privmsg); signal_add_last("ctcp action", (SIGNAL_FUNC) ctcp_action); signal_add("event nick", (SIGNAL_FUNC) event_nick); } void irc_queries_deinit(void) { - signal_remove("event privmsg", (SIGNAL_FUNC) event_privmsg); signal_remove("ctcp action", (SIGNAL_FUNC) ctcp_action); signal_remove("event nick", (SIGNAL_FUNC) event_nick); } diff --git a/src/irc/core/irc-servers.h b/src/irc/core/irc-servers.h index bb100f86..09f3f81d 100644 --- a/src/irc/core/irc-servers.h +++ b/src/irc/core/irc-servers.h @@ -68,6 +68,7 @@ struct _IRC_SERVER_REC { unsigned int motd_got:1; /* We've received MOTD */ unsigned int isupport_sent:1; /* Server has sent us an isupport reply */ unsigned int cap_complete:1; /* We've done the initial CAP negotiation */ + unsigned int sasl_success:1; /* Did we authenticate successfully ? */ int max_kicks_in_cmd; /* max. number of people to kick with one /KICK command */ int max_modes_in_cmd; /* max. number of mode changes in one /MODE command */ diff --git a/src/irc/core/sasl.c b/src/irc/core/sasl.c index a1c16cdd..1021bea4 100644 --- a/src/irc/core/sasl.c +++ b/src/irc/core/sasl.c @@ -48,6 +48,7 @@ static gboolean sasl_timeout(IRC_SERVER_REC *server) cap_finish_negotiation(server); server->sasl_timeout = 0; + server->sasl_success = FALSE; signal_emit("server sasl failure", 2, server, "The authentication timed out"); @@ -84,6 +85,8 @@ static void sasl_fail(IRC_SERVER_REC *server, const char *data, const char *from params = event_get_params(data, 2, NULL, &error); + server->sasl_success = FALSE; + signal_emit("server sasl failure", 2, server, error); /* Terminate the negotiation */ @@ -99,6 +102,8 @@ static void sasl_already(IRC_SERVER_REC *server, const char *data, const char *f server->sasl_timeout = 0; } + server->sasl_success = TRUE; + signal_emit("server sasl success", 1, server); /* We're already authenticated, do nothing */ @@ -112,6 +117,8 @@ static void sasl_success(IRC_SERVER_REC *server, const char *data, const char *f server->sasl_timeout = 0; } + server->sasl_success = TRUE; + signal_emit("server sasl success", 1, server); /* The authentication succeeded, time to finish the CAP negotiation */ diff --git a/src/perl/irc/Irc.xs b/src/perl/irc/Irc.xs index 8b3b0c45..41690010 100644 --- a/src/perl/irc/Irc.xs +++ b/src/perl/irc/Irc.xs @@ -32,6 +32,7 @@ static void perl_irc_server_fill_hash(HV *hv, IRC_SERVER_REC *server) (void) hv_store(hv, "isupport_sent", 13, newSViv(server->isupport_sent), 0); (void) hv_store(hv, "cap_complete", 12, newSViv(server->cap_complete), 0); + (void) hv_store(hv, "sasl_success", 12, newSViv(server->sasl_success), 0); av = newAV(); for (tmp = server->cap_supported; tmp != NULL; tmp = tmp->next) |