summaryrefslogtreecommitdiff
path: root/usr.bin/vi/cl
diff options
context:
space:
mode:
authorAnthony J. Bentley <bentley@cvs.openbsd.org>2016-03-17 03:44:06 +0000
committerAnthony J. Bentley <bentley@cvs.openbsd.org>2016-03-17 03:44:06 +0000
commit3970093b6ed158e1fb8a66b4de99a1c7093cdc96 (patch)
treef106e786afa4e1d6d5a8f1e643bf70928412987a /usr.bin/vi/cl
parentf9ae670b5345c6a8fb62d8b0864d2cb154cbc351 (diff)
Add error checking for COLUMNS/LINES environment variables.
It would be better to replace all the complicated existing code with a simple idiom, and this is being worked on. But for the moment, preventing vi from crashing is worthwhile. ok jung@
Diffstat (limited to 'usr.bin/vi/cl')
-rw-r--r--usr.bin/vi/cl/cl_term.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/usr.bin/vi/cl/cl_term.c b/usr.bin/vi/cl/cl_term.c
index 0f6eefe81c6..85ebf5d638a 100644
--- a/usr.bin/vi/cl/cl_term.c
+++ b/usr.bin/vi/cl/cl_term.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cl_term.c,v 1.21 2016/01/06 22:28:52 millert Exp $ */
+/* $OpenBSD: cl_term.c,v 1.22 2016/03/17 03:44:05 bentley Exp $ */
/*-
* Copyright (c) 1993, 1994
@@ -319,7 +319,8 @@ cl_ssize(SCR *sp, int sigwinch, size_t *rowp, size_t *colp, int *changedp)
struct winsize win;
size_t col, row;
int rval;
- char *p;
+ long lval;
+ char *p, *ep;
/* Assume it's changed. */
if (changedp != NULL)
@@ -413,10 +414,28 @@ noterm: if (row == 0)
* deleting the LINES and COLUMNS environment variables from their
* dot-files.
*/
- if ((p = getenv("LINES")) != NULL)
- row = strtol(p, NULL, 10);
- if ((p = getenv("COLUMNS")) != NULL)
- col = strtol(p, NULL, 10);
+ if ((p = getenv("LINES")) != NULL) {
+ errno = 0;
+ lval = strtol(p, &ep, 10);
+ if (p[0] == '\0' || *ep != '\0')
+ ;
+ else if ((errno == ERANGE && (lval == LONG_MAX || lval ==
+ LONG_MIN)) || (lval > INT_MAX || lval < 1))
+ ;
+ else
+ row = lval;
+ }
+ if ((p = getenv("COLUMNS")) != NULL) {
+ errno = 0;
+ lval = strtol(p, &ep, 10);
+ if (p[0] == '\0' || *ep != '\0')
+ ;
+ else if ((errno == ERANGE && (lval == LONG_MAX || lval ==
+ LONG_MIN)) || (lval > INT_MAX || lval < 1))
+ ;
+ else
+ col = lval;
+ }
if (rowp != NULL)
*rowp = row;