agetty: Prevent cursor escape
PATCH 1/1 agetty: Prevent cursor escape
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.
--- term-utils/agetty.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
term-utils/agetty.c +8 -1
@@ -2286,7 +2286,14 @@ static char *get_logname(struct issue *ie, struct options *op, struct termios *tif ((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 ; }
Signature · 1 line
2.45.2
Quoted 2 lines · Stanislav Brabec
term-utils/agetty.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
Applied, thanks.
term-utils/agetty.c static char *get_logname(struct issue *ie, struct options *op, struct termios *t · line 2294
Quoted 1 line
term-utils/agetty.c +1
-0+write_all (1 ,"^[" ,2 );
Not sure if we need anything more robust here. If you have access to the terminal, you can write whatever you want and it will be interpreted as a username (meaning non-terminal code will interpret it).
There is include/carefulputc.h:fputs_careful(), but it's currently based on FILE streams rather than file descriptors.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Dne 23. 07. 24 v 14:56 Karel Zak napsal(a):
Quoted 6 lines · Stanislav Brabec
term-utils/agetty.c static char *get_logname(struct issue *ie, struct options *op, struct termios *t · line 2294
Quoted 2 lines
term-utils/agetty.c +1
-0+write_all (1 ,"^[" ,2 );Not sure if we need anything more robust here. If you have access to the terminal, you can write whatever you want and it will be interpreted as a username (meaning non-terminal code will interpret it).
Anything better would be complicated. We are reading stdin byte after byte. So we need to do something with the yet unfinished sequence. And we cannot read more, as the select() guarantees just a single character. Ando this is just equal to ICANON | ECHOCTL terminal mode. Additionally, it returns behavior that was here before 8b58ffdd, but now processing network events better.
By the way, login is affected by the same problem. But in that case, it is the fault of pam. I proposed the same solution here. But in that case, it can be handled on the terminal level:
https://github.com/linux-pam/linux-pam/pull/816
Signature · 10 lines
Best Regards / S pozdravem, Stanislav Brabec software developer --------------------------------------------------------------------- SUSE LINUX, s. r. o. e-mail: [email protected] Křižíkova 148/34 (Corso IIa) tel: +420 284 084 060 186 00 Praha 8-Karlín fax: +420 284 084 001 Czech Republic http://www.suse.cz/ PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76