summaryrefslogtreecommitdiff
path: root/src/core/misc.c
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@irssi.org>2009-04-03 22:09:17 +0000
committerjilles <jilles@dbcabf3a-b0e7-0310-adc4-f8d773084564>2009-04-03 22:09:17 +0000
commitc4bd1631bb21bc522a80ec49f6e906b88561e354 (patch)
tree18c0a0d9df0036011f9eaedcf6586412039e682a /src/core/misc.c
parentbb92a2dbc765f365fe10054acc8f0f01e06a7f38 (diff)
downloadirssi-c4bd1631bb21bc522a80ec49f6e906b88561e354.zip
Make the time duration parser stricter.
This makes /set server_reconnect_time = 10min fail instead of setting the time to 0. git-svn-id: file:///var/www/svn.irssi.org/SVN/irssi/trunk@5057 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/core/misc.c')
-rw-r--r--src/core/misc.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/core/misc.c b/src/core/misc.c
index dffcac6c..e0df07e5 100644
--- a/src/core/misc.c
+++ b/src/core/misc.c
@@ -811,34 +811,45 @@ int nearest_power(int num)
int parse_time_interval(const char *time, int *msecs)
{
const char *desc;
- int number, sign, len, ret;
+ int number, sign, len, ret, digits;
*msecs = 0;
/* max. return value is around 24 days */
- number = 0; sign = 1; ret = TRUE;
- for (;;) {
- if (*time == '-') {
- sign = -sign;
+ number = 0; sign = 1; ret = TRUE; digits = FALSE;
+ while (i_isspace(*time))
+ time++;
+ if (*time == '-') {
+ sign = -sign;
+ time++;
+ while (i_isspace(*time))
time++;
- continue;
- }
-
+ }
+ for (;;) {
if (i_isdigit(*time)) {
number = number*10 + (*time - '0');
time++;
+ digits = TRUE;
continue;
}
+ if (!digits)
+ return FALSE;
+
/* skip punctuation */
- while (*time != '\0' && i_ispunct(*time))
+ while (*time != '\0' && i_ispunct(*time) && *time != '-')
time++;
/* get description */
for (len = 0, desc = time; i_isalpha(*time); time++)
len++;
+ while (i_isspace(*time))
+ time++;
+
if (len == 0) {
+ if (*time != '\0')
+ return FALSE;
*msecs += number * 1000; /* assume seconds */
*msecs *= sign;
return TRUE;
@@ -868,13 +879,14 @@ int parse_time_interval(const char *time, int *msecs)
}
/* skip punctuation */
- while (*time != '\0' && i_ispunct(*time))
+ while (*time != '\0' && i_ispunct(*time) && *time != '-')
time++;
if (*time == '\0')
break;
number = 0;
+ digits = FALSE;
}
*msecs *= sign;