From: Theodore Ts'o Date: Thu, 30 Jan 2014 21:19:01 +0000 (-0500) Subject: blkid: avoid potential integer overflow issues identified by Coverity X-Git-Tag: v1.42.10~82 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5bb4d0cec4492ca9941dc0af31d88239ed8e42a5;p=thirdparty%2Fe2fsprogs.git blkid: avoid potential integer overflow issues identified by Coverity Addresses-Coverity-Id: #1049157 Addresses-Coverity-Id: #1049158 Signed-off-by: "Theodore Ts'o" --- diff --git a/misc/blkid.c b/misc/blkid.c index c40de986b..55808af80 100644 --- a/misc/blkid.c +++ b/misc/blkid.c @@ -100,19 +100,27 @@ static int get_terminal_width(void) struct winsize w_win; #endif const char *cp; + int width = 80; #ifdef TIOCGSIZE - if (ioctl (0, TIOCGSIZE, &t_win) == 0) - return (t_win.ts_cols); + if (ioctl (0, TIOCGSIZE, &t_win) == 0) { + width = t_win.ts_cols; + goto got_it; + } #endif #ifdef TIOCGWINSZ - if (ioctl (0, TIOCGWINSZ, &w_win) == 0) - return (w_win.ws_col); + if (ioctl (0, TIOCGWINSZ, &w_win) == 0) { + width = w_win.ws_col; + goto got_it; + } #endif cp = getenv("COLUMNS"); if (cp) - return strtol(cp, NULL, 10); - return 80; + width = atoi(cp); +got_it: + if (width > 4096) + return 4096; /* sanity check */ + return width; } static int pretty_print_word(const char *str, int max_len,