[PATCH v2] lineedit: fix some tab completions written to stdout

Sertonix sertonix at posteo.net
Fri Nov 1 23:07:31 UTC 2024


In fd47f056765 (lineedit: print prompt and editing operations to stderr)
some output was left printing to stdout. This causes a race condition
between stderr and stdout which in some cases leads to output written in
the wrong places.

Downstream issue: https://gitlab.alpinelinux.org/alpine/aports/-/issues/16566
Fixes: fd47f056765

Signed-off-by: Sertonix <sertonix at posteo.net>
---
 The implicit '\n' doesn't apply to stderr so it needed to be explicit.

 libbb/lineedit.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 151208c1c..26f47f043 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -451,7 +451,7 @@ static void put_cur_glyph_and_inc_cursor(void)
 		 * have automargin (IOW: it is moving cursor to next line
 		 * by itself (which is wrong for VT-10x terminals)),
 		 * this will break things: there will be one extra empty line */
-		puts("\r"); /* + implicit '\n' */
+		fprintf(stderr, "\r\n");
 #else
 		/* VT-10x terminals don't wrap cursor to next line when last char
 		 * on the line is printed - cursor stays "over" this char.
@@ -1170,9 +1170,9 @@ static void showfiles(void)
 			);
 		}
 		if (ENABLE_UNICODE_SUPPORT)
-			puts(printable_string(matches[n]));
+			fprintf(stderr, "%s\n", printable_string(matches[n]));
 		else
-			puts(matches[n]);
+			fprintf(stderr, "%s\n", matches[n]);
 	}
 }
 
-- 
2.46.2



More information about the busybox mailing list