diff options
author | Jérémie Courrèges-Anglas <jca@wxcvbn.org> | 2014-03-03 21:25:09 +0100 |
---|---|---|
committer | Jérémie Courrèges-Anglas <jca@wxcvbn.org> | 2014-03-03 21:25:09 +0100 |
commit | 52e120f5533c93b0874cefd52b60bf65d6a640b9 (patch) | |
tree | 3adb994af8e8b1e45f5a74ac75b1694428527e41 /src | |
parent | 0dd5c323fae7881577963ce77012e317db19af88 (diff) | |
download | ratpoison-52e120f5533c93b0874cefd52b60bf65d6a640b9.zip |
Make read_number more strict, returning errors.
* use strtol, and warn about overflow or invalid input.
Diffstat (limited to 'src')
-rw-r--r-- | src/actions.c | 12 |
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; } |