mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
protect theme recursion
This commit is contained in:
parent
6d42c4f949
commit
12360fb2c0
@ -400,12 +400,15 @@ char *theme_format_expand_get(THEME_REC *theme, const char **format)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *theme_format_expand_data_rec(THEME_REC *theme, const char **format,
|
||||||
|
theme_rm_col default_fg, theme_rm_col default_bg,
|
||||||
|
theme_rm_col *save_last_fg, theme_rm_col *save_last_bg,
|
||||||
|
int flags, GTree *block_list);
|
||||||
|
|
||||||
/* expand a single {abstract ...data... } */
|
/* expand a single {abstract ...data... } */
|
||||||
static char *theme_format_expand_abstract(THEME_REC *theme,
|
static char *theme_format_expand_abstract(THEME_REC *theme, const char **formatp,
|
||||||
const char **formatp,
|
theme_rm_col *last_fg, theme_rm_col *last_bg, int flags,
|
||||||
theme_rm_col *last_fg,
|
GTree *block_list)
|
||||||
theme_rm_col *last_bg,
|
|
||||||
int flags)
|
|
||||||
{
|
{
|
||||||
GString *str;
|
GString *str;
|
||||||
const char *p, *format;
|
const char *p, *format;
|
||||||
@ -439,12 +442,20 @@ static char *theme_format_expand_abstract(THEME_REC *theme,
|
|||||||
}
|
}
|
||||||
*formatp = format+len;
|
*formatp = format+len;
|
||||||
|
|
||||||
|
if (block_list == NULL) {
|
||||||
|
block_list = g_tree_new_full((GCompareDataFunc) g_strcmp0, NULL, g_free, NULL);
|
||||||
|
} else {
|
||||||
|
g_tree_ref(block_list);
|
||||||
|
}
|
||||||
|
|
||||||
/* get the abstract data */
|
/* get the abstract data */
|
||||||
data = g_hash_table_lookup(theme->abstracts, abstract);
|
data = g_hash_table_lookup(theme->abstracts, abstract);
|
||||||
g_free(abstract);
|
if (data == NULL || g_tree_lookup(block_list, abstract) != NULL) {
|
||||||
if (data == NULL) {
|
|
||||||
/* unknown abstract, just display the data */
|
/* unknown abstract, just display the data */
|
||||||
data = "$0-";
|
data = "$0-";
|
||||||
|
g_free(abstract);
|
||||||
|
} else {
|
||||||
|
g_tree_insert(block_list, abstract, abstract);
|
||||||
}
|
}
|
||||||
abstract = g_strdup(data);
|
abstract = g_strdup(data);
|
||||||
|
|
||||||
@ -488,18 +499,17 @@ static char *theme_format_expand_abstract(THEME_REC *theme,
|
|||||||
|
|
||||||
/* abstract may itself contain abstracts or replaces */
|
/* abstract may itself contain abstracts or replaces */
|
||||||
p = abstract;
|
p = abstract;
|
||||||
ret = theme_format_expand_data(theme, &p, default_fg, default_bg,
|
ret = theme_format_expand_data_rec(theme, &p, default_fg, default_bg, last_fg, last_bg,
|
||||||
last_fg, last_bg,
|
flags | EXPAND_FLAG_LASTCOLOR_ARG, block_list);
|
||||||
flags | EXPAND_FLAG_LASTCOLOR_ARG);
|
|
||||||
g_free(abstract);
|
g_free(abstract);
|
||||||
|
g_tree_unref(block_list);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* expand the data part in {abstract data} */
|
static char *theme_format_expand_data_rec(THEME_REC *theme, const char **format,
|
||||||
char *theme_format_expand_data(THEME_REC *theme, const char **format,
|
|
||||||
theme_rm_col default_fg, theme_rm_col default_bg,
|
theme_rm_col default_fg, theme_rm_col default_bg,
|
||||||
theme_rm_col *save_last_fg, theme_rm_col *save_last_bg,
|
theme_rm_col *save_last_fg, theme_rm_col *save_last_bg,
|
||||||
int flags)
|
int flags, GTree *block_list)
|
||||||
{
|
{
|
||||||
GString *str;
|
GString *str;
|
||||||
char *ret, *abstract;
|
char *ret, *abstract;
|
||||||
@ -545,9 +555,8 @@ char *theme_format_expand_data(THEME_REC *theme, const char **format,
|
|||||||
break; /* error */
|
break; /* error */
|
||||||
|
|
||||||
/* get a single {...} */
|
/* get a single {...} */
|
||||||
abstract = theme_format_expand_abstract(theme, format,
|
abstract = theme_format_expand_abstract(theme, format, &last_fg, &last_bg,
|
||||||
&last_fg, &last_bg,
|
recurse_flags, block_list);
|
||||||
recurse_flags);
|
|
||||||
if (abstract != NULL) {
|
if (abstract != NULL) {
|
||||||
g_string_append(str, abstract);
|
g_string_append(str, abstract);
|
||||||
g_free(abstract);
|
g_free(abstract);
|
||||||
@ -565,6 +574,15 @@ char *theme_format_expand_data(THEME_REC *theme, const char **format,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* expand the data part in {abstract data} */
|
||||||
|
char *theme_format_expand_data(THEME_REC *theme, const char **format, theme_rm_col default_fg,
|
||||||
|
theme_rm_col default_bg, theme_rm_col *save_last_fg,
|
||||||
|
theme_rm_col *save_last_bg, int flags)
|
||||||
|
{
|
||||||
|
return theme_format_expand_data_rec(theme, format, default_fg, default_bg, save_last_bg,
|
||||||
|
save_last_bg, flags, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
#define IS_OLD_FORMAT(code, last_fg, last_bg) \
|
#define IS_OLD_FORMAT(code, last_fg, last_bg) \
|
||||||
(((code) == 'n' && (last_fg) == 'n' && (last_bg) == 'n') || \
|
(((code) == 'n' && (last_fg) == 'n' && (last_bg) == 'n') || \
|
||||||
((code) != 'n' && ((code) == (last_fg) || (code) == (last_bg))))
|
((code) != 'n' && ((code) == (last_fg) || (code) == (last_bg))))
|
||||||
|
Loading…
Reference in New Issue
Block a user