зеркало из https://github.com/github/putty.git
Fix the line-resizing bug in scroll(). (Thanks to RDB for pointing
it out. A line was removed from the scrollback, cleared, and placed at the bottom of the screen. Fine, except that the clearing process assumed the line was the right length already, and thanks to lazy resizing this wasn't necessarily the case. Segfaults and memory corruption ensued.) [originally from svn r1129]
This commit is contained in:
Родитель
2aad72ab3e
Коммит
aca29ffb7b
47
terminal.c
47
terminal.c
|
@ -200,6 +200,31 @@ static void deselect(void);
|
|||
static FILE *lgfp = NULL;
|
||||
static void logtraffic(unsigned char c, int logmode);
|
||||
|
||||
/*
|
||||
* Resize a line to make it `cols' columns wide.
|
||||
*/
|
||||
unsigned long *resizeline(unsigned long *line, int cols)
|
||||
{
|
||||
int i, oldlen;
|
||||
unsigned long lineattrs;
|
||||
|
||||
if (line[0] != (unsigned long)cols) {
|
||||
/*
|
||||
* This line is the wrong length, which probably means it
|
||||
* hasn't been accessed since a resize. Resize it now.
|
||||
*/
|
||||
oldlen = line[0];
|
||||
lineattrs = line[oldlen + 1];
|
||||
line = srealloc(line, TSIZE * (2 + cols));
|
||||
line[0] = cols;
|
||||
for (i = oldlen; i < cols; i++)
|
||||
line[i + 1] = ERASE_CHAR;
|
||||
line[cols + 1] = lineattrs & LATTR_MODE;
|
||||
}
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
/*
|
||||
* Retrieve a line of the screen or of the scrollback, according to
|
||||
* whether the y coordinate is non-negative or negative
|
||||
|
@ -207,9 +232,9 @@ static void logtraffic(unsigned char c, int logmode);
|
|||
*/
|
||||
unsigned long *lineptr(int y, int lineno)
|
||||
{
|
||||
unsigned long *line, lineattrs;
|
||||
unsigned long *line, *newline;
|
||||
tree234 *whichtree;
|
||||
int i, treeindex, oldlen;
|
||||
int treeindex;
|
||||
|
||||
if (y >= 0) {
|
||||
whichtree = screen;
|
||||
|
@ -223,20 +248,10 @@ unsigned long *lineptr(int y, int lineno)
|
|||
/* We assume that we don't screw up and retrieve something out of range. */
|
||||
assert(line != NULL);
|
||||
|
||||
if (line[0] != cols) {
|
||||
/*
|
||||
* This line is the wrong length, which probably means it
|
||||
* hasn't been accessed since a resize. Resize it now.
|
||||
*/
|
||||
oldlen = line[0];
|
||||
lineattrs = line[oldlen + 1];
|
||||
newline = resizeline(line, cols);
|
||||
if (newline != line) {
|
||||
delpos234(whichtree, treeindex);
|
||||
line = srealloc(line, TSIZE * (2 + cols));
|
||||
line[0] = cols;
|
||||
for (i = oldlen; i < cols; i++)
|
||||
line[i + 1] = ERASE_CHAR;
|
||||
line[cols + 1] = lineattrs & LATTR_MODE;
|
||||
addpos234(whichtree, line, treeindex);
|
||||
addpos234(whichtree, newline, treeindex);
|
||||
}
|
||||
|
||||
return line + 1;
|
||||
|
@ -568,6 +583,7 @@ static void scroll(int topline, int botline, int lines, int sb)
|
|||
if (lines < 0) {
|
||||
while (lines < 0) {
|
||||
line = delpos234(screen, botline);
|
||||
line = resizeline(line, cols);
|
||||
for (i = 0; i < cols; i++)
|
||||
line[i + 1] = erase_char;
|
||||
line[cols + 1] = 0;
|
||||
|
@ -610,6 +626,7 @@ static void scroll(int topline, int botline, int lines, int sb)
|
|||
addpos234(scrollback, line, sblen);
|
||||
line = line2;
|
||||
}
|
||||
line = resizeline(line, cols);
|
||||
for (i = 0; i < cols; i++)
|
||||
line[i + 1] = erase_char;
|
||||
line[cols + 1] = 0;
|
||||
|
|
Загрузка…
Ссылка в новой задаче