diff options
author | Eric Andersen <andersen@codepoet.org> | 2004-03-23 23:15:36 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2004-03-23 23:15:36 +0000 |
commit | 97310d025390e96f34140cff13034fcd2b5da18f (patch) | |
tree | be9b3406b9b0598d0bc42d6912a7855f7ee11819 | |
parent | 6bb80870b839cc812d55b28f886bf3e001e4a00e (diff) | |
download | busybox-w32-97310d025390e96f34140cff13034fcd2b5da18f.tar.gz busybox-w32-97310d025390e96f34140cff13034fcd2b5da18f.tar.bz2 busybox-w32-97310d025390e96f34140cff13034fcd2b5da18f.zip |
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.c | 2 | ||||
-rw-r--r-- | libbb/get_terminal_width_height.c | 2 | ||||
-rw-r--r-- | util-linux/more.c | 4 |
3 files changed, 5 insertions, 3 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c index f7fa9a110..8b5065ac6 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c | |||
@@ -982,7 +982,7 @@ extern int ls_main(int argc, char **argv) | |||
982 | 982 | ||
983 | #ifdef CONFIG_FEATURE_AUTOWIDTH | 983 | #ifdef CONFIG_FEATURE_AUTOWIDTH |
984 | /* Obtain the terminal width. */ | 984 | /* Obtain the terminal width. */ |
985 | get_terminal_width_height(0, &terminal_width, NULL); | 985 | get_terminal_width_height(fileno(stdout), &terminal_width, NULL); |
986 | /* Go one less... */ | 986 | /* Go one less... */ |
987 | terminal_width--; | 987 | terminal_width--; |
988 | #endif | 988 | #endif |
diff --git a/libbb/get_terminal_width_height.c b/libbb/get_terminal_width_height.c index ef90463fb..7a1af6dc1 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) | |||
36 | { | 36 | { |
37 | struct winsize win = { 0, 0, 0, 0 }; | 37 | struct winsize win = { 0, 0, 0, 0 }; |
38 | #ifdef CONFIG_FEATURE_AUTOWIDTH | 38 | #ifdef CONFIG_FEATURE_AUTOWIDTH |
39 | if (ioctl(0, TIOCGWINSZ, &win) != 0) { | 39 | if (ioctl(fd, TIOCGWINSZ, &win) != 0) { |
40 | win.ws_row = 24; | 40 | win.ws_row = 24; |
41 | win.ws_col = 80; | 41 | win.ws_col = 80; |
42 | } | 42 | } |
diff --git a/util-linux/more.c b/util-linux/more.c index d7b7ce22f..04b29de17 100644 --- a/util-linux/more.c +++ b/util-linux/more.c | |||
@@ -67,6 +67,7 @@ extern int more_main(int argc, char **argv) | |||
67 | int please_display_more_prompt = -1; | 67 | int please_display_more_prompt = -1; |
68 | struct stat st; | 68 | struct stat st; |
69 | FILE *file; | 69 | FILE *file; |
70 | FILE *in_file = stdin; | ||
70 | int len, page_height; | 71 | int len, page_height; |
71 | 72 | ||
72 | argc--; | 73 | argc--; |
@@ -78,6 +79,7 @@ extern int more_main(int argc, char **argv) | |||
78 | cin = fopen(CURRENT_TTY, "r"); | 79 | cin = fopen(CURRENT_TTY, "r"); |
79 | if (!cin) | 80 | if (!cin) |
80 | cin = bb_xfopen(CONSOLE_DEV, "r"); | 81 | cin = bb_xfopen(CONSOLE_DEV, "r"); |
82 | in_file = cin; | ||
81 | please_display_more_prompt = 0; | 83 | please_display_more_prompt = 0; |
82 | #ifdef CONFIG_FEATURE_USE_TERMIOS | 84 | #ifdef CONFIG_FEATURE_USE_TERMIOS |
83 | getTermSettings(fileno(cin), &initial_settings); | 85 | getTermSettings(fileno(cin), &initial_settings); |
@@ -108,7 +110,7 @@ extern int more_main(int argc, char **argv) | |||
108 | if(please_display_more_prompt>0) | 110 | if(please_display_more_prompt>0) |
109 | please_display_more_prompt = 0; | 111 | please_display_more_prompt = 0; |
110 | 112 | ||
111 | get_terminal_width_height(0, &terminal_width, &terminal_height); | 113 | get_terminal_width_height(fileno(in_file), &terminal_width, &terminal_height); |
112 | if (terminal_height > 4) | 114 | if (terminal_height > 4) |
113 | terminal_height -= 2; | 115 | terminal_height -= 2; |
114 | if (terminal_width > 0) | 116 | if (terminal_width > 0) |