Bug 115231

Summary: drivers/tty/n_tty.c:eraser does not handle fullwidth character in ICANON mode
Product: Drivers Reporter: Ray Song (i)
Component: SerialAssignee: Russell King (rmk)
Status: NEW ---    
Severity: normal CC: egmont
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: * Subsystem:
Regression: No Bisected commit-id:

Description Ray Song 2016-03-24 04:25:23 UTC
Start "cat" (to ensure it is in the canonical mode), enter a CJK character (other fullwidth character also applie), then press Backspace and expect the cursor to retreat by 2 columns, however, the cursor retreated by 1 column.

I confirm that the noncanonical mode handles fullwidth characters correctly with the following commands:

vte
strace -e read,write -p $(pgrep -n vte) |& grep 5

# bash (readline) ~ICANON,  two "\b"
write(5, "\177", 1)                     = 1
read(5, "\10\10\33[0m\33[0m \33[0m \10\10", 8176) = 18
...
# cat ICANON,     one "\b"
write(5, "\177", 1)                     = 1
read(5, "\10 \10", 8176)                = 3

It seems that the following lines do not handle fullwidth character correctly:

drivers/tty/n_tty.c:1047
static void eraser(unsigned char c, struct tty_struct *tty)
.......

				if (iscntrl(c) && L_ECHOCTL(tty)) {
					echo_char_raw('\b', ldata);
					echo_char_raw(' ', ldata);
					echo_char_raw('\b', ldata);
				}
				if (!iscntrl(c) || L_ECHOCTL(tty)) {
					echo_char_raw('\b', ldata);
					echo_char_raw(' ', ldata);
					echo_char_raw('\b', ldata);
				}