aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-10-27 09:03:24 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-10-27 09:03:24 +0000
commit9bc0f50defc28a31a2d214e654ec48e2a1bcc897 (patch)
treecd34a619db35dccb76043c1bf118d297e17ac436 /libbb
parent8b039ac7df3ae06554165c79429b5d06240080c1 (diff)
downloadbusybox-w32-9bc0f50defc28a31a2d214e654ec48e2a1bcc897.tar.gz
busybox-w32-9bc0f50defc28a31a2d214e654ec48e2a1bcc897.tar.bz2
busybox-w32-9bc0f50defc28a31a2d214e654ec48e2a1bcc897.zip
get_terminal_width_height: do not pass insanely large values
git-svn-id: svn://busybox.net/trunk/busybox@16452 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb')
-rw-r--r--libbb/xfuncs.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index 1144a67c6..c72265003 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -281,6 +281,8 @@ off_t fdlength(int fd)
281 281
282 if (ioctl(fd, BLKGETSIZE, &size) >= 0) return size*512; 282 if (ioctl(fd, BLKGETSIZE, &size) >= 0) return size*512;
283 283
284 // FIXME: explain why lseek(SEEK_END) is not used here!
285
284 // If not, do a binary search for the last location we can read. (Some 286 // If not, do a binary search for the last location we can read. (Some
285 // block devices don't do BLKGETSIZE right.) 287 // block devices don't do BLKGETSIZE right.)
286 288
@@ -382,7 +384,8 @@ DIR *xopendir(const char *path)
382// Die with an error message if we can't daemonize. 384// Die with an error message if we can't daemonize.
383void xdaemon(int nochdir, int noclose) 385void xdaemon(int nochdir, int noclose)
384{ 386{
385 if (daemon(nochdir, noclose)) bb_perror_msg_and_die("daemon"); 387 if (daemon(nochdir, noclose))
388 bb_perror_msg_and_die("daemon");
386} 389}
387#endif 390#endif
388 391
@@ -416,23 +419,31 @@ void xstat(char *name, struct stat *stat_buf)
416} 419}
417 420
418/* It is perfectly ok to pass in a NULL for either width or for 421/* It is perfectly ok to pass in a NULL for either width or for
419 * * height, in which case that value will not be set. */ 422 * height, in which case that value will not be set. */
420int get_terminal_width_height(int fd, int *width, int *height) 423int get_terminal_width_height(int fd, int *width, int *height)
421{ 424{
422 struct winsize win = { 0, 0, 0, 0 }; 425 struct winsize win = { 0, 0, 0, 0 };
423 int ret = ioctl(fd, TIOCGWINSZ, &win); 426 int ret = ioctl(fd, TIOCGWINSZ, &win);
424 if (!win.ws_row) { 427
425 char *s = getenv("LINES"); 428 if (height) {
426 if (s) win.ws_row = atoi(s); 429 if (!win.ws_row) {
430 char *s = getenv("LINES");
431 if (s) win.ws_row = atoi(s);
432 }
433 if (win.ws_row <= 1 || win.ws_row >= 30000)
434 win.ws_row = 24;
435 *height = (int) win.ws_row;
427 } 436 }
428 if (win.ws_row <= 1) win.ws_row = 24; 437
429 if (!win.ws_col) { 438 if (width) {
430 char *s = getenv("COLUMNS"); 439 if (!win.ws_col) {
431 if (s) win.ws_col = atoi(s); 440 char *s = getenv("COLUMNS");
441 if (s) win.ws_col = atoi(s);
442 }
443 if (win.ws_col <= 1 || win.ws_col >= 30000)
444 win.ws_col = 80;
445 *width = (int) win.ws_col;
432 } 446 }
433 if (win.ws_col <= 1) win.ws_col = 80;
434 if (height) *height = (int) win.ws_row;
435 if (width) *width = (int) win.ws_col;
436 447
437 return ret; 448 return ret;
438} 449}