mirror of
https://github.com/irssi/irssi.git
synced 2026-08-11 04:43:34 +02:00
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
This commit is contained in:
parent
4ea8f3141e
commit
115a7fc355
3 changed files with 25 additions and 3 deletions
|
|
@ -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 ? "" :
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue