diff options
author | Guillem Jover <guillem@debian.org> | 2016-03-01 02:30:59 +0100 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2016-04-01 00:58:13 +0200 |
commit | 3d258742dfe5cd18e4e06a5fbd855b99bb95046e (patch) | |
tree | edf0c40f56dfaed51418a3385f73e07d08c8b21e /src/querycmd.c | |
parent | ecd4baa091619cbbdd70043129dd992573580371 (diff) | |
download | dpkg-3d258742dfe5cd18e4e06a5fbd855b99bb95046e.tar.gz |
dpkg-query: Be more strict when parsing the COLUMNS environment variable
Use strtol() instead of atoi() which does not make it possible to check
for many error conditions.
Diffstat (limited to 'src/querycmd.c')
-rw-r--r-- | src/querycmd.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/querycmd.c b/src/querycmd.c index 22d635cdd..2494f72ef 100644 --- a/src/querycmd.c +++ b/src/querycmd.c @@ -32,6 +32,8 @@ #if HAVE_LOCALE_H #include <locale.h> #endif +#include <errno.h> +#include <limits.h> #include <string.h> #include <fcntl.h> #include <dirent.h> @@ -63,14 +65,17 @@ static int opt_loadavail = 0; static int getwidth(void) { int fd; - int res; + long res; struct winsize ws; const char *columns; + char *endptr; columns = getenv("COLUMNS"); if (columns) { - res = atoi(columns); - if (res > 0) + errno = 0; + res = strtol(columns, &endptr, 10); + if (errno != 0 && columns != endptr && *endptr == '\0' && + res > 0 && res < INT_MAX) return res; } |