summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen2004-03-23 23:15:36 +0000
committerEric Andersen2004-03-23 23:15:36 +0000
commit97310d025390e96f34140cff13034fcd2b5da18f (patch)
treebe9b3406b9b0598d0bc42d6912a7855f7ee11819
parent6bb80870b839cc812d55b28f886bf3e001e4a00e (diff)
downloadbusybox-97310d025390e96f34140cff13034fcd2b5da18f.zip
busybox-97310d025390e96f34140cff13034fcd2b5da18f.tar.gz
Brian Pomerantz writes:
I've noticed a bug in the "autowidth" feature more, and is probably in others. The call to the function get_terminal_width_height() passes in a file descriptor but that file descriptor is never used, instead the ioctl() is called with 0. In more_main() the call to get_terminal_width_height() passes 0 as the file descriptor instead of fileno(cin). This isn't a problem when you more a file (e.g. "more /etc/passwd") but when you pipe a file to it (e.g. "cat /etc/passwd | more") the size of the terminal cannot be determined because file descriptor 0 is not a terminal. The fix is simple, I've attached a patch for more.c and get_terminal_width_height.c. BAPper
-rw-r--r--coreutils/ls.c2
-rw-r--r--libbb/get_terminal_width_height.c2
-rw-r--r--util-linux/more.c4
3 files changed, 5 insertions, 3 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c
index f7fa9a1..8b5065a 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -982,7 +982,7 @@ extern int ls_main(int argc, char **argv)
#ifdef CONFIG_FEATURE_AUTOWIDTH
/* Obtain the terminal width. */
- get_terminal_width_height(0, &terminal_width, NULL);
+ get_terminal_width_height(fileno(stdout), &terminal_width, NULL);
/* Go one less... */
terminal_width--;
#endif
diff --git a/libbb/get_terminal_width_height.c b/libbb/get_terminal_width_height.c
index ef90463..7a1af6d 100644
--- a/libbb/get_terminal_width_height.c
+++ b/libbb/get_terminal_width_height.c
@@ -36,7 +36,7 @@ void get_terminal_width_height(int fd, int *width, int *height)
{
struct winsize win = { 0, 0, 0, 0 };
#ifdef CONFIG_FEATURE_AUTOWIDTH
- if (ioctl(0, TIOCGWINSZ, &win) != 0) {
+ if (ioctl(fd, TIOCGWINSZ, &win) != 0) {
win.ws_row = 24;
win.ws_col = 80;
}
diff --git a/util-linux/more.c b/util-linux/more.c
index d7b7ce2..04b29de 100644
--- a/util-linux/more.c
+++ b/util-linux/more.c
@@ -67,6 +67,7 @@ extern int more_main(int argc, char **argv)
int please_display_more_prompt = -1;
struct stat st;
FILE *file;
+ FILE *in_file = stdin;
int len, page_height;
argc--;
@@ -78,6 +79,7 @@ extern int more_main(int argc, char **argv)
cin = fopen(CURRENT_TTY, "r");
if (!cin)
cin = bb_xfopen(CONSOLE_DEV, "r");
+ in_file = cin;
please_display_more_prompt = 0;
#ifdef CONFIG_FEATURE_USE_TERMIOS
getTermSettings(fileno(cin), &initial_settings);
@@ -108,7 +110,7 @@ extern int more_main(int argc, char **argv)
if(please_display_more_prompt>0)
please_display_more_prompt = 0;
- get_terminal_width_height(0, &terminal_width, &terminal_height);
+ get_terminal_width_height(fileno(in_file), &terminal_width, &terminal_height);
if (terminal_height > 4)
terminal_height -= 2;
if (terminal_width > 0)