cfdisk was getting characters without checking ERR return code, causing an endless while loop in do_curses_fdisk() or in other functions when the terminal is lost. Signed-off-by: Francesco Cosoleto <cosoleto@xxxxxxxxx> --- fdisk/cfdisk.c | 20 ++++++++++++++++---- 1 files changed, 16 insertions(+), 4 deletions(-) diff --git a/fdisk/cfdisk.c b/fdisk/cfdisk.c index 1e078a9..3363da4 100644 --- a/fdisk/cfdisk.c +++ b/fdisk/cfdisk.c @@ -428,7 +428,7 @@ fdexit(int ret) { static int get_string(char *str, int len, char *def) { size_t cells = 0, i = 0; - int x, y, key; + int x, y; int use_def = FALSE; wint_t c; @@ -445,13 +445,21 @@ get_string(char *str, int len, char *def) { refresh(); + while (1) { #if !defined(HAVE_SLCURSES_H) && !defined(HAVE_SLANG_SLCURSES_H) && \ defined(HAVE_LIBNCURSESW) && defined(HAVE_WIDECHAR) - while ((key = get_wch(&c)) != ERR && - c != '\r' && c != '\n' && c != KEY_ENTER) { + if (get_wch(&c) == ERR) #else - while ((c = getch()) != '\n' && c != CR) { + if ((c = getch()) == ERR) #endif + if (!isatty(STDIN_FILENO)) + exit(2); + else + break; + + if (c == '\r' || c == '\n' || c == KEY_ENTER) + break; + switch (c) { case ESC: move(y, x); @@ -1131,6 +1139,10 @@ menuSelect( int y, int x, struct MenuItem *menuItems, int itemLength, refresh(); key = getch(); + if (key == ERR) + if (!isatty(STDIN_FILENO)) + exit(2); + /* Clear out all prompts and such */ clear_warning(); for (i = y; i < ylast; i++) { -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html