From 82e40d211902d486d2871a1bc691d1768927efd5 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Sat, 18 Apr 2015 18:28:39 +0000 Subject: Convert many atoi() calls to strtonum(), adding range checks and failure handling along the way. Reviews by Brendan MacDonell, Jeremy Devenport, florian, doug, millert --- usr.bin/sed/process.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'usr.bin/sed') 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; } -- cgit v1.2.3