Module Name: src
Committed By: christos
Date: Tue Oct 23 16:49:13 UTC 2018
Modified Files:
src/lib/libedit: refresh.c
Log Message:
Apply revisions 1.21, 1.22 from OpenBSD:
In re_fastputc(), set lastline to the new line, not the previous
line so it gets initialized properly. Fixes a crash in bc with
MALLOC_OPTIONS=UJ. OK deraadt@, committing on behalf of yasuoka@
Initialize "old" screen buffer lines before use; otherwise, they would
never get NUL-terminated and cause read buffer overruns.
This fixes for example segfaults in sftp(1) that could be triggered
by typing in an extremely long string (more than one line - the longer,
the likelier to crash), then hitting backspace once.
Problem reported and patch OK'ed by sthen@.
XXX: pullup-8
To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/lib/libedit/refresh.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libedit/refresh.c
diff -u src/lib/libedit/refresh.c:1.54 src/lib/libedit/refresh.c:1.55
--- src/lib/libedit/refresh.c:1.54 Fri Jun 30 16:26:52 2017
+++ src/lib/libedit/refresh.c Tue Oct 23 12:49:13 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: refresh.c,v 1.54 2017/06/30 20:26:52 kre Exp $ */
+/* $NetBSD: refresh.c,v 1.55 2018/10/23 16:49:13 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: refresh.c,v 1.54 2017/06/30 20:26:52 kre Exp $");
+__RCSID("$NetBSD: refresh.c,v 1.55 2018/10/23 16:49:13 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -1090,7 +1090,10 @@ re_refresh_cursor(EditLine *el)
static void
re_fastputc(EditLine *el, wint_t c)
{
- int w = wcwidth(c);
+ wchar_t *lastline;
+ int w;
+
+ w = wcwidth(c);
while (w > 1 && el->el_cursor.h + w > el->el_terminal.t_size.h)
re_fastputc(el, ' ');
@@ -1112,17 +1115,19 @@ re_fastputc(EditLine *el, wint_t c)
*/
if (el->el_cursor.v + 1 >= el->el_terminal.t_size.v) {
int i, lins = el->el_terminal.t_size.v;
- wchar_t *firstline = el->el_display[0];
+ lastline = el->el_display[0];
for(i = 1; i < lins; i++)
el->el_display[i - 1] = el->el_display[i];
- re__copy_and_pad(firstline, L"", (size_t)0);
- el->el_display[i - 1] = firstline;
+ el->el_display[i - 1] = lastline;
} else {
el->el_cursor.v++;
el->el_refresh.r_oldcv++;
+ lastline = el->el_display[++el->el_refresh.r_oldcv];
}
+ re__copy_and_pad(lastline, L"", (size_t)el->el_terminal.t_size.h);
+
if (EL_HAS_AUTO_MARGINS) {
if (EL_HAS_MAGIC_MARGINS) {
terminal__putc(el, ' ');