summaryrefslogtreecommitdiff
path: root/src/actions.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/actions.c')
-rw-r--r--src/actions.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/actions.c b/src/actions.c
index 5ac17a2..a19146a 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -2185,9 +2185,19 @@ read_number (struct argspec *spec, struct sbuf *s, struct cmdarg **arg)
if (input)
{
+ char *ep;
+ long lval;
+
+ errno = 0;
+ lval = strtol (input, &ep, 10);
+ if (input[0] == '\0' || *ep != '\0')
+ return cmdret_new (RET_FAILURE, "malformed number `%s'", input);
+ if ((errno == ERANGE && (lval == LONG_MAX || lval == LONG_MIN)) ||
+ (lval > INT_MAX || lval < INT_MIN))
+ return cmdret_new (RET_FAILURE, "out of range number `%s'", input);
*arg = xmalloc (sizeof(struct cmdarg));
(*arg)->type = arg_NUMBER;
- (*arg)->arg.number = strtol (input, NULL, 10);
+ (*arg)->arg.number = lval;
(*arg)->string = input;
return NULL;
}