Prevent potential integer overflow
PR: 192971 Submitted by: David Carlier <david.carlier@hardenedbsd.org>
This commit is contained in:
parent
d3f9e6a743
commit
d4bf4151a5
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=285437
@ -158,6 +158,7 @@ main(int argc, char *argv[])
|
|||||||
struct winsize win;
|
struct winsize win;
|
||||||
int ch, fts_options, notused;
|
int ch, fts_options, notused;
|
||||||
char *p;
|
char *p;
|
||||||
|
const char *errstr = NULL;
|
||||||
#ifdef COLORLS
|
#ifdef COLORLS
|
||||||
char termcapbuf[1024]; /* termcap definition buffer */
|
char termcapbuf[1024]; /* termcap definition buffer */
|
||||||
char tcapbuf[512]; /* capability buffer */
|
char tcapbuf[512]; /* capability buffer */
|
||||||
@ -170,7 +171,7 @@ main(int argc, char *argv[])
|
|||||||
if (isatty(STDOUT_FILENO)) {
|
if (isatty(STDOUT_FILENO)) {
|
||||||
termwidth = 80;
|
termwidth = 80;
|
||||||
if ((p = getenv("COLUMNS")) != NULL && *p != '\0')
|
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 &&
|
else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) != -1 &&
|
||||||
win.ws_col > 0)
|
win.ws_col > 0)
|
||||||
termwidth = win.ws_col;
|
termwidth = win.ws_col;
|
||||||
@ -180,9 +181,12 @@ main(int argc, char *argv[])
|
|||||||
/* retrieve environment variable, in case of explicit -C */
|
/* retrieve environment variable, in case of explicit -C */
|
||||||
p = getenv("COLUMNS");
|
p = getenv("COLUMNS");
|
||||||
if (p)
|
if (p)
|
||||||
termwidth = atoi(p);
|
termwidth = strtonum(p, 0, INT_MAX, &errstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (errstr)
|
||||||
|
termwidth = 80;
|
||||||
|
|
||||||
fts_options = FTS_PHYSICAL;
|
fts_options = FTS_PHYSICAL;
|
||||||
if (getenv("LS_SAMESORT"))
|
if (getenv("LS_SAMESORT"))
|
||||||
f_samesort = 1;
|
f_samesort = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user