summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@irssi.org>2009-02-21 21:17:51 +0000
committerjilles <jilles@dbcabf3a-b0e7-0310-adc4-f8d773084564>2009-02-21 21:17:51 +0000
commitcb1f07352af92688983563998f9251ab20cac821 (patch)
tree9b01c36bec2240c4ba98f24bd5ed6a5a6ec60bd2 /src/core
parent946e7784b00c9051013b996bd09dcaf144cf250c (diff)
downloadirssi-cb1f07352af92688983563998f9251ab20cac821.zip
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
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ignore.c2
-rw-r--r--src/core/levels.c8
-rw-r--r--src/core/levels.h2
-rw-r--r--src/core/log.c2
-rw-r--r--src/core/settings.c8
5 files changed, 16 insertions, 6 deletions
diff --git a/src/core/ignore.c b/src/core/ignore.c
index f69a900e..ef7221b7 100644
--- a/src/core/ignore.c
+++ b/src/core/ignore.c
@@ -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);
diff --git a/src/core/levels.c b/src/core/levels.c
index 73743352..3cc00e95 100644
--- a/src/core/levels.c
+++ b/src/core/levels.c
@@ -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;
diff --git a/src/core/levels.h b/src/core/levels.h
index dec7afe7..9f7e588f 100644
--- a/src/core/levels.h
+++ b/src/core/levels.h
@@ -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);
diff --git a/src/core/log.c b/src/core/log.c
index 67ff24c1..106aafb8 100644
--- a/src/core/log.c
+++ b/src/core/log.c
@@ -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);
diff --git a/src/core/settings.c b/src/core/settings.c
index cb196bd1..bfcead3e 100644
--- a/src/core/settings.c
+++ b/src/core/settings.c
@@ -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;
}