diff mbox series

[wrynose] busybox: fix garbled ash tab completion

Message ID 20261127-busybox-lineedit-tab-completion-v1-1-b03e71a045b9@gmail.com
State New
Headers show
Series [wrynose] busybox: fix garbled ash tab completion | expand

Commit Message

Alex Kiernan Nov. 27, 2026, 10:21 a.m. UTC
busybox 1.37 moved line editing to stderr (fd47f056765a) but left the tab
completion list on stdout, so a double-tab completion garbles the command
line and leaves the cursor a line low. Backport the two upstream fixes,
which are in 1.38.

AI-Generated: Claude Code (Claude Opus 5.5)
Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
---
Double-tab completion in ash garbles the command line on busybox 1.37:
the completion list went to stdout while line editing moved to stderr.
Upstream fixed it in 1.38; this backports the two fixes.

master has 1.38 already. The same patch applies to whinlatter and
walnascar, which also carry 1.37.0.
---
 ...-fix-printing-lines-during-tab-completion.patch | 37 ++++++++++++++++++++++
 ...02-lineedit-fix-left-over-print-to-stdout.patch | 33 +++++++++++++++++++
 meta/recipes-core/busybox/busybox_1.37.0.bb        |  2 ++
 3 files changed, 72 insertions(+)


---
base-commit: 16a03ed6c2db2fa1d7edac4f288a74958a00eb9f
change-id: 20261127-busybox-lineedit-tab-completion-5fb30518b040

Best regards,
--  
Alex Kiernan <alex.kiernan@gmail.com>
diff mbox series

Patch

diff --git a/meta/recipes-core/busybox/busybox/0001-lineedit-fix-printing-lines-during-tab-completion.patch b/meta/recipes-core/busybox/busybox/0001-lineedit-fix-printing-lines-during-tab-completion.patch
new file mode 100644
index 000000000000..59ced37744d2
--- /dev/null
+++ b/meta/recipes-core/busybox/busybox/0001-lineedit-fix-printing-lines-during-tab-completion.patch
@@ -0,0 +1,37 @@ 
+From 7e469dc3697df810973394b5cfaf81fbe48bc330 Mon Sep 17 00:00:00 2001
+From: Ahmad Fatoum <a.fatoum@pengutronix.de>
+Date: Tue, 15 Apr 2025 23:45:54 +0200
+Subject: [PATCH] lineedit: fix printing lines during tab completion
+
+Indentation and escape characters are all output to stderr now, but the
+matches themself remained on stdout leading to garbled output on Tab
+completion.
+
+Print the results to stderr as well to fix this.
+
+Fixes: fd47f056765a ("lineedit: print prompt and editing operations to stderr")
+Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
+Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
+Upstream-Status: Backport [https://git.busybox.net/busybox/commit/?id=37abfb919dfa92132bc7a14c583016a46026729b]
+Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
+---
+ libbb/lineedit.c | 5 +++--
+ 1 file changed, 3 insertions(+), 2 deletions(-)
+
+diff --git a/libbb/lineedit.c b/libbb/lineedit.c
+index 543a3f11c3e4..1f4b011008b6 100644
+--- a/libbb/lineedit.c
++++ b/libbb/lineedit.c
+@@ -1170,9 +1170,10 @@ static void showfiles(void)
+ 			);
+ 		}
+ 		if (ENABLE_UNICODE_SUPPORT)
+-			puts(printable_string(matches[n]));
++			fputs(printable_string(matches[n]), stderr);
+ 		else
+-			puts(matches[n]);
++			fputs(matches[n], stderr);
++		bb_putchar_stderr('\n');
+ 	}
+ }
+ 
diff --git a/meta/recipes-core/busybox/busybox/0002-lineedit-fix-left-over-print-to-stdout.patch b/meta/recipes-core/busybox/busybox/0002-lineedit-fix-left-over-print-to-stdout.patch
new file mode 100644
index 000000000000..03edb41f4573
--- /dev/null
+++ b/meta/recipes-core/busybox/busybox/0002-lineedit-fix-left-over-print-to-stdout.patch
@@ -0,0 +1,33 @@ 
+From d19748647d03ca9a067119ce6e040fbd7b45c695 Mon Sep 17 00:00:00 2001
+From: Ahmad Fatoum <a.fatoum@pengutronix.de>
+Date: Tue, 15 Apr 2025 23:45:55 +0200
+Subject: [PATCH] lineedit: fix left-over print to stdout
+
+There's code printing to stderr both before and after the single call to
+puts inside put_cur_glyph_and_inc_cursor().
+
+This is likely an oversight as we want everything to go through the
+same file descriptor, so switch it over to fputs.
+
+Fixes: fd47f056765a ("lineedit: print prompt and editing operations to stderr")
+Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
+Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
+Upstream-Status: Backport [https://git.busybox.net/busybox/commit/?id=952a7b9cececa314b2f5a9827dac8213b1a74460]
+Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
+---
+ libbb/lineedit.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/libbb/lineedit.c b/libbb/lineedit.c
+index 1f4b011008b6..206fc36ef5c0 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' */
++		fputs("\r\n", stderr);
+ #else
+ 		/* VT-10x terminals don't wrap cursor to next line when last char
+ 		 * on the line is printed - cursor stays "over" this char.
diff --git a/meta/recipes-core/busybox/busybox_1.37.0.bb b/meta/recipes-core/busybox/busybox_1.37.0.bb
index b020c923be32..6cabd6252653 100644
--- a/meta/recipes-core/busybox/busybox_1.37.0.bb
+++ b/meta/recipes-core/busybox/busybox_1.37.0.bb
@@ -67,6 +67,8 @@  SRC_URI = "https://busybox.net/downloads/busybox-${PV}.tar.bz2;name=tarball \
            file://CVE-2026-29004-01.patch \
            file://CVE-2026-29004-02.patch \
            file://CVE-2026-38754.patch \
+           file://0001-lineedit-fix-printing-lines-during-tab-completion.patch \
+           file://0002-lineedit-fix-left-over-print-to-stdout.patch \
            "
 SRC_URI:append:libc-musl = " file://musl.cfg"
 SRC_URI:append:x86-64 = " file://sha_accel.cfg"