core: fix infinite loop in evaluation of strings (closes #1183)

v2.8-utf8proc
Sébastien Helleu 2018-04-17 20:27:48 +02:00
parent 7877e1b8c2
commit 76f3be5260
3 changed files with 26 additions and 7 deletions

View File

@ -28,6 +28,7 @@ New features::
Bug fixes::
* core: fix infinite loop in evaluation of strings (issue #1183)
* core: change default value of option weechat.look.window_title from "WeeChat ${info:version}" to empty string (issue #1182)
* irc: always set nick away status on WHO response (sent manually or automatically with server option "away_check")
* irc: fix a crash when calling the function hdata_string on the "prefix" variable in the nick

View File

@ -717,14 +717,28 @@ char *
eval_replace_vars (const char *expr, struct t_eval_context *eval_context)
{
const char *no_replace_prefix_list[] = { "if:", NULL };
char *result;
return string_replace_with_callback (expr,
eval_context->prefix,
eval_context->suffix,
no_replace_prefix_list,
&eval_replace_vars_cb,
eval_context,
NULL);
eval_context->recursion_count++;
if (eval_context->recursion_count < EVAL_RECURSION_MAX)
{
result = string_replace_with_callback (expr,
eval_context->prefix,
eval_context->suffix,
no_replace_prefix_list,
&eval_replace_vars_cb,
eval_context,
NULL);
}
else
{
result = strdup ("");
}
eval_context->recursion_count--;
return result;
}
/*
@ -1253,6 +1267,7 @@ eval_expression (const char *expr, struct t_hashtable *pointers,
eval_context.prefix = default_prefix;
eval_context.suffix = default_suffix;
eval_context.regex = NULL;
eval_context.recursion_count = 0;
/*
* set window/buffer with pointer to current window/buffer

View File

@ -28,6 +28,8 @@
#define EVAL_DEFAULT_PREFIX "${"
#define EVAL_DEFAULT_SUFFIX "}"
#define EVAL_RECURSION_MAX 32
struct t_hashtable;
enum t_eval_logical_op
@ -69,6 +71,7 @@ struct t_eval_context
const char *prefix;
const char *suffix;
struct t_eval_regex *regex;
int recursion_count;
};
extern int eval_is_true (const char *value);