]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
terminal-util: extra safety checks when parsing $COLUMNS or $LINES (#10314)
authorLennart Poettering <lennart@poettering.net>
Tue, 9 Oct 2018 07:49:04 +0000 (09:49 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 9 Oct 2018 07:49:04 +0000 (16:49 +0900)
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.

src/basic/terminal-util.c

index a6671542701f2dd30ec0913e2fd09fe52560552a..c2aa75c6a82a80ab36abdc14a70e3e7a97191d57 100644 (file)
@@ -819,11 +819,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;
@@ -853,11 +853,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;