diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2011-02-23 16:21:18 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2011-02-23 16:21:18 +0100 |
commit | e3cc291448a4e33c33324fd1e780df1d6848c9bd (patch) | |
tree | 436e82b66232a6f392bcdbcae458b587d9b22e5d /src/plugins | |
parent | b4ccd82a9dc982dcbdac13f3506f8db89f15a725 (diff) | |
download | weechat-e3cc291448a4e33c33324fd1e780df1d6848c9bd.zip |
Fix crash when adding rmodifier with invalid regex
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/rmodifier/rmodifier-command.c | 8 | ||||
-rw-r--r-- | src/plugins/rmodifier/rmodifier.c | 50 |
2 files changed, 22 insertions, 36 deletions
diff --git a/src/plugins/rmodifier/rmodifier-command.c b/src/plugins/rmodifier/rmodifier-command.c index 564643768..b51af0526 100644 --- a/src/plugins/rmodifier/rmodifier-command.c +++ b/src/plugins/rmodifier/rmodifier-command.c @@ -128,7 +128,7 @@ rmodifier_command_cb (void *data, struct t_gui_buffer *buffer, int argc, _("%sError: missing arguments for \"%s\" " "command"), weechat_prefix ("error"), "rmodifier"); - return WEECHAT_RC_ERROR; + return WEECHAT_RC_OK; } ptr_rmodifier = rmodifier_new (argv[2], argv[3], argv_eol[5], argv[4]); if (!ptr_rmodifier) @@ -137,7 +137,7 @@ rmodifier_command_cb (void *data, struct t_gui_buffer *buffer, int argc, _("%s%s: error creating rmodifier \"%s\""), weechat_prefix ("error"), RMODIFIER_PLUGIN_NAME, argv[2]); - return WEECHAT_RC_ERROR; + return WEECHAT_RC_OK; } /* create config option */ ptr_option = weechat_config_search_option (rmodifier_config_file, @@ -165,7 +165,7 @@ rmodifier_command_cb (void *data, struct t_gui_buffer *buffer, int argc, _("%sError: missing arguments for \"%s\" " "command"), weechat_prefix ("error"), "rmodifier"); - return WEECHAT_RC_ERROR; + return WEECHAT_RC_OK; } if (weechat_strcasecmp (argv[2], "-all") == 0) { @@ -217,7 +217,7 @@ rmodifier_command_cb (void *data, struct t_gui_buffer *buffer, int argc, _("%sError: \"-yes\" argument is required for " "restoring default rmodifiers (security reason)"), weechat_prefix ("error")); - return WEECHAT_RC_ERROR; + return WEECHAT_RC_OK; } return WEECHAT_RC_OK; } diff --git a/src/plugins/rmodifier/rmodifier.c b/src/plugins/rmodifier/rmodifier.c index 289e738bd..bb738393f 100644 --- a/src/plugins/rmodifier/rmodifier.c +++ b/src/plugins/rmodifier/rmodifier.c @@ -212,35 +212,6 @@ rmodifier_modifier_cb (void *data, const char *modifier, } /* - * rmodifier_create_regex: create regex for a rmodifier - */ - -void -rmodifier_create_regex (struct t_rmodifier *rmodifier) -{ - if (rmodifier->regex) - { - regfree (rmodifier->regex); - free (rmodifier->regex); - } - - rmodifier->regex = malloc (sizeof (*rmodifier->regex)); - if (!rmodifier->regex) - return; - - if (regcomp (rmodifier->regex, rmodifier->str_regex, - REG_EXTENDED | REG_ICASE) != 0) - { - weechat_printf (NULL, - _("%s%s: error compiling regular expression \"%s\""), - weechat_prefix ("error"), RMODIFIER_PLUGIN_NAME, - rmodifier->str_regex); - free (rmodifier->regex); - return; - } -} - -/* * rmodifier_hook_modifiers: hook modifiers for a rmodifier */ @@ -284,11 +255,27 @@ rmodifier_new (const char *name, const char *modifiers, const char *str_regex, const char *groups) { struct t_rmodifier *new_rmodifier, *ptr_rmodifier; + regex_t *regex; if (!name || !name[0] || !modifiers || !modifiers[0] || !str_regex || !str_regex[0]) return NULL; + regex = malloc (sizeof (*regex)); + if (!regex) + return NULL; + + if (regcomp (regex, str_regex, + REG_EXTENDED | REG_ICASE) != 0) + { + weechat_printf (NULL, + _("%s%s: error compiling regular expression \"%s\""), + weechat_prefix ("error"), RMODIFIER_PLUGIN_NAME, + str_regex); + free (regex); + return NULL; + } + ptr_rmodifier = rmodifier_search (name); if (ptr_rmodifier) rmodifier_free (ptr_rmodifier); @@ -300,11 +287,10 @@ rmodifier_new (const char *name, const char *modifiers, const char *str_regex, new_rmodifier->hooks = NULL; new_rmodifier->modifiers = strdup (modifiers); new_rmodifier->str_regex = strdup (str_regex); - new_rmodifier->regex = NULL; + new_rmodifier->regex = regex; new_rmodifier->groups = strdup ((groups) ? groups : ""); - /* create regex and modifiers */ - rmodifier_create_regex (new_rmodifier); + /* create modifiers */ rmodifier_hook_modifiers (new_rmodifier); if (rmodifier_list) |