From a0a71efde02e10e36d06d106b3513358d29842dc Mon Sep 17 00:00:00 2001 From: Viktor Mihajlovski Date: Thu, 24 Mar 2022 10:17:50 +0100 Subject: [PATCH] fdasd: Fix endless menu loop on EOF MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hitting CTRL-D anywhere will cause fdasd to go into an endless loop displaying the main menu over and over again. Killing fdasd (e.g. via CTR-C) is the only way out. The issue is that read_line() is just ignoring the resulting EOF condition on stdin. Subsequent invocations of read_line() will return immediately and thus cause the loop. A simple fix is to reset stdin after EOF. A caller of read_line() will see the same behavior as for EOL with no input. Signed-off-by: Viktor Mihajlovski Reviewed-by: Jan Höppner Signed-off-by: Jan Höppner --- fdasd/fdasd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fdasd/fdasd.c b/fdasd/fdasd.c index a6064cd9..28898be7 100644 --- a/fdasd/fdasd.c +++ b/fdasd/fdasd.c @@ -408,8 +408,10 @@ static int read_line(void) { bzero(line_buffer, LINE_LENGTH); line_ptr = line_buffer; - if (!fgets(line_buffer, LINE_LENGTH, stdin)) + if (!fgets(line_buffer, LINE_LENGTH, stdin)) { + clearerr(stdin); return 0; + } while (*line_ptr && !isgraph(*line_ptr)) line_ptr++;