summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@irssi.org>2009-02-21 17:20:13 +0000
committerjilles <jilles@dbcabf3a-b0e7-0310-adc4-f8d773084564>2009-02-21 17:20:13 +0000
commit115a7fc355d5dd9aeb4714d46809ea774512ff82 (patch)
tree615f304dbe244e4eea6639769aa6cd5e055fd615 /src
parent4ea8f3141eaf162838ba2b602e81cf8c5ac7d258 (diff)
downloadirssi-115a7fc355d5dd9aeb4714d46809ea774512ff82.zip
Reject obviously invalid numbers in /set.
A limitation of the settings model is that any value that fits in an int is accepted, e.g. negative port numbers. git-svn-id: file:///var/www/svn.irssi.org/SVN/irssi/trunk@5017 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src')
-rw-r--r--src/fe-common/core/fe-settings.c26
-rw-r--r--src/fe-common/core/module-formats.c1
-rw-r--r--src/fe-common/core/module-formats.h1
3 files changed, 25 insertions, 3 deletions
diff --git a/src/fe-common/core/fe-settings.c b/src/fe-common/core/fe-settings.c
index 45cff2ba..1f3277f6 100644
--- a/src/fe-common/core/fe-settings.c
+++ b/src/fe-common/core/fe-settings.c
@@ -76,6 +76,23 @@ static void set_boolean(const char *key, const char *value)
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_NOT_TOGGLE);
}
+static void set_int(const char *key, const char *value)
+{
+ char *endp;
+ long longval;
+ int error;
+
+ errno = 0;
+ longval = strtol(value, &endp, 10);
+ error = errno;
+ while (isspace((unsigned char)*endp))
+ endp++;
+ if (error != 0 || *endp != '\0' || longval < INT_MIN || longval > INT_MAX)
+ printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_INVALID_NUMBER);
+ else
+ settings_set_int(key, (int)longval);
+}
+
/* SYNTAX: SET [-clear | -default] [<key> [<value>]] */
static void cmd_set(char *data)
{
@@ -111,9 +128,12 @@ static void cmd_set(char *data)
set_boolean(key, value);
break;
case SETTING_TYPE_INT:
- settings_set_int(key, clear ? 0 :
- set_default ? rec->default_value.v_int :
- atoi(value));
+ if (clear)
+ settings_set_int(key, 0);
+ else if (set_default)
+ settings_set_int(key, rec->default_value.v_int);
+ else
+ set_int(key, value);
break;
case SETTING_TYPE_STRING:
settings_set_str(key, clear ? "" :
diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c
index 10ada9ec..4857ba51 100644
--- a/src/fe-common/core/module-formats.c
+++ b/src/fe-common/core/module-formats.c
@@ -215,6 +215,7 @@ FORMAT_REC fecommon_core_formats[] = {
{ "chan_not_synced", "Channel not fully synchronized yet, try again after a while", 0 },
{ "illegal_proto", "Command isn't designed for the chat protocol of the active server", 0 },
{ "not_good_idea", "Doing this is not a good idea. Add -YES option to command if you really mean it", 0 },
+ { "invalid_number", "Invalid number", 0 },
{ "invalid_time", "Invalid timestamp", 0 },
{ "invalid_level", "Invalid message level", 0 },
{ "invalid_size", "Invalid size", 0 },
diff --git a/src/fe-common/core/module-formats.h b/src/fe-common/core/module-formats.h
index 64dde0f9..18bf91f5 100644
--- a/src/fe-common/core/module-formats.h
+++ b/src/fe-common/core/module-formats.h
@@ -184,6 +184,7 @@ enum {
TXT_CHAN_NOT_SYNCED,
TXT_ILLEGAL_PROTO,
TXT_NOT_GOOD_IDEA,
+ TXT_INVALID_NUMBER,
TXT_INVALID_TIME,
TXT_INVALID_LEVEL,
TXT_INVALID_SIZE,