Date: Mon, 13 Jul 2015 05:56:28 +0000 (UTC) From: Baptiste Daroussin <bapt@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r285437 - head/bin/ls Message-ID: <201507130556.t6D5uSox096858@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <david.carlier@hardenedbsd.org> 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;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201507130556.t6D5uSox096858>