From owner-svn-src-all@freebsd.org Mon Jul 13 05:56:28 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CD4A499BD6B; Mon, 13 Jul 2015 05:56:28 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B99B91085; Mon, 13 Jul 2015 05:56:28 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t6D5uS5K096859; Mon, 13 Jul 2015 05:56:28 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by repo.freebsd.org (8.14.9/8.14.9/Submit) id t6D5uSox096858; Mon, 13 Jul 2015 05:56:28 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <201507130556.t6D5uSox096858@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Mon, 13 Jul 2015 05:56:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r285437 - head/bin/ls X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Jul 2015 05:56:28 -0000 Author: bapt Date: Mon Jul 13 05:56:27 2015 New Revision: 285437 URL: https://svnweb.freebsd.org/changeset/base/285437 Log: Prevent potential integer overflow PR: 192971 Submitted by: David Carlier Modified: head/bin/ls/ls.c Modified: head/bin/ls/ls.c ============================================================================== --- head/bin/ls/ls.c Mon Jul 13 05:13:39 2015 (r285436) +++ head/bin/ls/ls.c Mon Jul 13 05:56:27 2015 (r285437) @@ -158,6 +158,7 @@ main(int argc, char *argv[]) struct winsize win; int ch, fts_options, notused; char *p; + const char *errstr = NULL; #ifdef COLORLS char termcapbuf[1024]; /* termcap definition buffer */ char tcapbuf[512]; /* capability buffer */ @@ -170,7 +171,7 @@ main(int argc, char *argv[]) if (isatty(STDOUT_FILENO)) { termwidth = 80; if ((p = getenv("COLUMNS")) != NULL && *p != '\0') - termwidth = atoi(p); + termwidth = strtonum(p, 0, INT_MAX, &errstr); else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) != -1 && win.ws_col > 0) termwidth = win.ws_col; @@ -180,9 +181,12 @@ main(int argc, char *argv[]) /* retrieve environment variable, in case of explicit -C */ p = getenv("COLUMNS"); if (p) - termwidth = atoi(p); + termwidth = strtonum(p, 0, INT_MAX, &errstr); } + if (errstr) + termwidth = 80; + fts_options = FTS_PHYSICAL; if (getenv("LS_SAMESORT")) f_samesort = 1;