in get_key_buffer(), if we fail to get a character over MAX_BUF_SIZE

times in a row, hang up regardless of the value of errno; this fixes a
problem where nano doesn't terminate properly under xterm if the user
su's to root, runs nano, and then closes the terminal window


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3309 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
David Lawrence Ramsey 2006-03-19 19:25:29 +00:00
parent 1ec74ee30c
commit 9149325400
3 changed files with 16 additions and 4 deletions

View File

@ -58,6 +58,12 @@ CVS code -
set errno to EINVAL as well as return -1 if they fail. This
matches the manual page. (DLR)
- winio.c:
get_key_buffer()
- If we fail to get a character over MAX_BUF_SIZE times in a
row, hang up regardless of the value of errno. This fixes a
problem where nano doesn't terminate properly under xterm if
the user su's to root, runs nano, and then closes the terminal
window. (DLR, found by John <acocaracha@gmail.com>)
parse_kbinput()
- Interpret Shift-Begin, Shift-Delete, Shift-End, Shift-Home,
Shift-Insert, and Shift-Suspend as Begin, Delete, End, Home,

View File

@ -590,7 +590,7 @@ typedef struct rcoption {
* counting the blank lines at their ends. */
#define MAX_SEARCH_HISTORY 100
/* The maximum number of bytes we read into a buffer at one time. */
/* The maximum number of bytes buffered at one time. */
#define MAX_BUF_SIZE 128
#endif /* !NANO_H */

View File

@ -122,7 +122,7 @@ void reset_kbinput(void)
* default keystroke buffer is empty. */
void get_key_buffer(WINDOW *win)
{
int input;
int input, errcount;
/* If the keystroke buffer isn't empty, get out. */
if (key_buffer != NULL)
@ -137,10 +137,16 @@ void get_key_buffer(WINDOW *win)
* screen updates. */
doupdate();
errcount = 0;
while ((input = wgetch(win)) == ERR) {
errcount++;
/* If errno is EIO, it means that the input source that we were
* using is gone, so die gracefully. */
if (errno == EIO)
* using is gone, so die gracefully. If we've failed to get a
* character over MAX_BUF_SIZE times in a row, it can mean the
* same thing regardless of the value of errno, so die
* gracefully then too. */
if (errno == EIO || errcount > MAX_BUF_SIZE)
handle_hupterm(0);
}