diff options
author | Baptiste Daroussin <bapt@FreeBSD.org> | 2015-07-13 05:56:27 +0000 |
---|---|---|
committer | Baptiste Daroussin <bapt@FreeBSD.org> | 2015-07-13 05:56:27 +0000 |
commit | d4bf4151a577a4b76bacf23c08065f6acf0e2c5f (patch) | |
tree | ac06a28fdfe3028885f1f2d296b4c6187c6335b1 | |
parent | d3f9e6a7439390ceea343ca6784eb756a6e28cf4 (diff) | |
download | src-d4bf4151a577a4b76bacf23c08065f6acf0e2c5f.tar.gz src-d4bf4151a577a4b76bacf23c08065f6acf0e2c5f.zip |
Prevent potential integer overflow
PR: 192971
Submitted by: David Carlier <david.carlier@hardenedbsd.org>
Notes
Notes:
svn path=/head/; revision=285437
-rw-r--r-- | bin/ls/ls.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/bin/ls/ls.c b/bin/ls/ls.c index 926d2bccaef5..df8cc2d79db6 100644 --- a/bin/ls/ls.c +++ b/bin/ls/ls.c @@ -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; |