1
0
mirror of https://github.com/irssi/irssi.git synced 2025-01-03 14:56:47 -05:00

Reject invalid level specifications in /set.

Most of these have names that end in "_level".


git-svn-id: file:///var/www/svn.irssi.org/SVN/irssi/trunk@5021 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Jilles Tjoelker 2009-02-21 21:17:51 +00:00 committed by jilles
parent 946e7784b0
commit cb1f07352a
12 changed files with 26 additions and 12 deletions

View File

@ -395,7 +395,7 @@ static void read_ignores(void)
rec->mask = g_strdup(config_node_get_str(node, "mask", NULL));
rec->pattern = g_strdup(config_node_get_str(node, "pattern", NULL));
rec->level = level2bits(config_node_get_str(node, "level", ""));
rec->level = level2bits(config_node_get_str(node, "level", ""), NULL);
rec->exception = config_node_get_bool(node, "exception", FALSE);
rec->regexp = config_node_get_bool(node, "regexp", FALSE);
rec->fullword = config_node_get_bool(node, "fullword", FALSE);

View File

@ -81,11 +81,14 @@ int level_get(const char *level)
return match;
}
int level2bits(const char *level)
int level2bits(const char *level, int *errorp)
{
char *orig, *str, *ptr;
int ret, singlelevel, negative;
if (errorp != NULL)
*errorp = FALSE;
g_return_val_if_fail(level != NULL, 0);
if (*level == '\0')
@ -107,7 +110,8 @@ int level2bits(const char *level)
if (singlelevel != 0) {
ret = !negative ? (ret | singlelevel) :
(ret & ~singlelevel);
}
} else if (errorp != NULL)
*errorp = TRUE;
while (*str == ' ') str++;
if (*str == '\0') break;

View File

@ -40,7 +40,7 @@ enum {
};
int level_get(const char *level);
int level2bits(const char *level);
int level2bits(const char *level, int *errorp);
char *bits2level(int bits);
int combine_level(int dest, const char *src);

View File

@ -540,7 +540,7 @@ static void log_read_config(void)
log->handle = -1;
log->fname = g_strdup(node->key);
log->autoopen = config_node_get_bool(node, "auto_open", FALSE);
log->level = level2bits(config_node_get_str(node, "level", 0));
log->level = level2bits(config_node_get_str(node, "level", 0), NULL);
signal_emit("log config read", 2, log, node);

View File

@ -134,7 +134,7 @@ int settings_get_level(const char *key)
const char *str;
str = settings_get_str_type(key, SETTING_TYPE_LEVEL);
return str == NULL ? 0 : level2bits(str);
return str == NULL ? 0 : level2bits(str, NULL);
}
int settings_get_size(const char *key)
@ -355,6 +355,12 @@ int settings_set_time(const char *key, const char *value)
int settings_set_level(const char *key, const char *value)
{
int iserror;
(void)level2bits(value, &iserror);
if (iserror)
return FALSE;
iconfig_node_set_str(settings_get_node(key), key, value);
return TRUE;
}

View File

@ -81,7 +81,7 @@ static void cmd_echo(const char *data, void *server, WI_ITEM_REC *item)
levelstr = g_hash_table_lookup(optlist, "level");
level = levelstr == NULL ? 0 :
level2bits(g_hash_table_lookup(optlist, "level"));
level2bits(g_hash_table_lookup(optlist, "level"), NULL);
if (level == 0) level = MSGLEVEL_CRAP;
winname = g_hash_table_lookup(optlist, "window");

View File

@ -513,7 +513,7 @@ static void handle_exec(const char *args, GHashTable *optlist,
rec->name = g_strdup(g_hash_table_lookup(optlist, "name"));
level = g_hash_table_lookup(optlist, "level");
rec->level = level == NULL ? MSGLEVEL_CLIENTCRAP : level2bits(level);
rec->level = level == NULL ? MSGLEVEL_CLIENTCRAP : level2bits(level, NULL);
rec->read_tag = g_input_add(rec->in, G_INPUT_READ,
(GInputFunction) sig_exec_input_reader,

View File

@ -92,7 +92,7 @@ static void cmd_log_open(const char *data)
return;
if (*fname == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
level = level2bits(levels);
level = level2bits(levels, NULL);
log = log_create_rec(fname, level != 0 ? level : MSGLEVEL_ALL);
/* -<server tag> */

View File

@ -576,7 +576,7 @@ static void cmd_hilight(const char *data)
}
rec->level = (levelarg == NULL || *levelarg == '\0') ? 0 :
level2bits(replace_chars(levelarg, ',', ' '));
level2bits(replace_chars(levelarg, ',', ' '), NULL);
rec->priority = priorityarg == NULL ? 0 : atoi(priorityarg);
if (g_hash_table_lookup(optlist, "line") != NULL) {

View File

@ -134,7 +134,7 @@ static void sig_layout_restore(void)
window->immortal = config_node_get_bool(node, "immortal", FALSE);
window_set_name(window, config_node_get_str(node, "name", NULL));
window_set_history(window, config_node_get_str(node, "history_name", NULL));
window_set_level(window, level2bits(config_node_get_str(node, "level", "")));
window_set_level(window, level2bits(config_node_get_str(node, "level", ""), NULL));
window->servertag = g_strdup(config_node_get_str(node, "servertag", NULL));
window->theme_name = g_strdup(config_node_get_str(node, "theme", NULL));

View File

@ -146,7 +146,7 @@ static void cmd_scrollback_levelclear(const char *data)
levelarg = g_hash_table_lookup(optlist, "level");
level = (levelarg == NULL || *levelarg == '\0') ? 0 :
level2bits(replace_chars(levelarg, ',', ' '));
level2bits(replace_chars(levelarg, ',', ' '), NULL);
if (level == 0) {
cmd_params_free(free_arg);
return;

View File

@ -492,6 +492,10 @@ OUTPUT:
int
level2bits(str)
char *str
CODE:
RETVAL = level2bits(str, NULL);
OUTPUT:
RETVAL
void
bits2level(bits)