[PATCH] agetty: Prevent cursor escape

Stanislav Brabec <[email protected]>
Newsgroups org.kernel.vger.util-linux
Message-ID <[email protected]>
Starting with 5de97519, it is possible to escape the login dialog on the
screen by arrow characters or using escape sequences.

Since full processing of escape sequences and ignore them would be
complicated, use a work around: instead of sending ESC to output, send a
printable character.

It could cause a rendering regression in a very obscure condition: compiled
without IUTF8, encoding is ISO-11548-1 and BRAILLE PATTERN DOTS-1245 is
part of login name. I believe that it is out of supported combinations.

Signed-off-by: Stanislav Brabec <[email protected]>
---
 term-utils/agetty.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/term-utils/agetty.c b/term-utils/agetty.c
index 275c59362..e20e7a454 100644
--- a/term-utils/agetty.c
+++ b/term-utils/agetty.c
@@ -2286,7 +2286,14 @@ static char *get_logname(struct issue *ie, struct options *op, struct termios *t
 				if ((size_t)(bp - logname) >= sizeof(logname) - 1)
 					log_err(_("%s: input overrun"), op->tty);
 				if ((tp->c_lflag & ECHO) == 0)
-					write_all(1, &c, 1);	/* echo the character */
+					/* Visualize escape sequence instead of its execution */
+					if (ascval == CTL('['))
+						/* Ideally it should be "\xe2\x90\x9b"
+						 * if (op->flags & (F_UTF8)),
+						 * but only some fonts contain it */
+						write_all(1, "^[", 2);
+					else
+						write_all(1, &c, 1);	/* echo the character */
 				*bp++ = ascval;			/* and store it */
 				break;
 			}
-- 
2.45.2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.