summaryrefslogtreecommitdiff
path: root/usr.bin/sed
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2015-04-18 18:28:39 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2015-04-18 18:28:39 +0000
commit82e40d211902d486d2871a1bc691d1768927efd5 (patch)
tree73caeece4da00dad32b1e62383474772aae90893 /usr.bin/sed
parenta15dfcc7862a97d34cf8fed2bb1292c14721e771 (diff)
Convert many atoi() calls to strtonum(), adding range checks and failure
handling along the way. Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert
Diffstat (limited to 'usr.bin/sed')
-rw-r--r--usr.bin/sed/process.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/usr.bin/sed/process.c b/usr.bin/sed/process.c
index 12385b844a4..aa7ea51d0c4 100644
--- a/usr.bin/sed/process.c
+++ b/usr.bin/sed/process.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: process.c,v 1.22 2015/04/13 05:11:23 deraadt Exp $ */
+/* $OpenBSD: process.c,v 1.23 2015/04/18 18:28:37 deraadt Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
@@ -457,12 +457,14 @@ lputs(char *s)
static int termwidth = -1;
if (termwidth == -1) {
+ termwidth = 0;
if ((p = getenv("COLUMNS")))
- termwidth = atoi(p);
- else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 &&
+ termwidth = strtonum(p, 0, INT_MAX, NULL);
+ if (termwidth == 0 &&
+ ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 &&
win.ws_col > 0)
termwidth = win.ws_col;
- else
+ if (termwidth == 0)
termwidth = 60;
}