From: Nicolas Pitre Date: Mon, 25 Feb 2013 01:06:09 +0000 (-0500) Subject: tty vt: fix character insertion overflow X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a883b70d8e0a88278c0a1f80753b4dc99962b541;p=GitHub%2Fexynos8895%2Fandroid_kernel_samsung_universal8895.git tty vt: fix character insertion overflow Commit 81732c3b2fed ("tty vt: Fix line garbage in virtual console on command line edition") broke insert_char() in multiple ways. Then commit b1a925f44a3a ("tty vt: Fix a regression in command line edition") partially fixed it. However, the buffer being moved is still too large and overflowing beyond the end of the current line, corrupting existing characters on the next line. Example test case: echo -e "abc\nde\x1b[A\x1b[4h \x1b[4l\x1b[B" Expected result: ab c de Current result: ab c e Needless to say that this is very annoying when inserting words in the middle of paragraphs with certain text editors. Signed-off-by: Nicolas Pitre Cc: Jean-François Moine Cc: Greg Kroah-Hartman Cc: Signed-off-by: Linus Torvalds --- diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 1a2728034599..6c4abeaf690f 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -539,7 +539,7 @@ static void insert_char(struct vc_data *vc, unsigned int nr) { unsigned short *p = (unsigned short *) vc->vc_pos; - scr_memmovew(p + nr, p, (vc->vc_cols - vc->vc_x) * 2); + scr_memmovew(p + nr, p, (vc->vc_cols - vc->vc_x - nr) * 2); scr_memsetw(p, vc->vc_video_erase_char, nr * 2); vc->vc_need_wrap = 0; if (DO_UPDATE(vc))