summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-10-09 09:49:04 +0200
committerSven Eden <sven.eden@prydeworx.com>2018-10-29 10:18:29 +0100
commit7e174f4ebccb5725e32dd5b78385ca0d41395c2c (patch)
tree640ef07ff6eeb5b595b7a9eae070c30df33503e1
parente5ac9d202b9a8189a34cecf2529afd72bc1ff024 (diff)
terminal-util: extra safety checks when parsing $COLUMNS or $LINES (#10314)
Let's make sure the integers we parse out are not larger than USHRT_MAX. This is a good idea as the kernel's TIOCSWINSZ ioctl for sizing terminals can't take larger values, and we shouldn't risk an overflow. (cherry picked from commit d09a71356e3ed78be7cef3cd7d9919dc77508b41)
-rw-r--r--src/basic/terminal-util.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c
index f8623f9fd..d8e5d0d2e 100644
--- a/src/basic/terminal-util.c
+++ b/src/basic/terminal-util.c
@@ -830,11 +830,11 @@ unsigned columns(void) {
if (e)
(void) safe_atoi(e, &c);
- if (c <= 0)
+ if (c <= 0 || c > USHRT_MAX) {
c = fd_columns(STDOUT_FILENO);
-
- if (c <= 0)
- c = 80;
+ if (c <= 0)
+ c = 80;
+ }
cached_columns = c;
return cached_columns;
@@ -864,11 +864,11 @@ unsigned lines(void) {
if (e)
(void) safe_atoi(e, &l);
- if (l <= 0)
+ if (l <= 0 || l > USHRT_MAX) {
l = fd_lines(STDOUT_FILENO);
-
- if (l <= 0)
- l = 24;
+ if (l <= 0)
+ l = 24;
+ }
cached_lines = l;
return cached_lines;