Merge pull request #16155 from zeertzjq/fix-redr-border-corruption

fix(float): fix potential heap corruption in win_redr_border
This commit is contained in:
Björn Linse
2021-11-06 22:32:28 +01:00
committed by GitHub
3 changed files with 51 additions and 3 deletions

View File

@@ -5655,7 +5655,9 @@ static void win_redr_border(win_T *wp)
int ic = (i == 0 && !adj[3] && chars[6][0]) ? 6 : 5; int ic = (i == 0 && !adj[3] && chars[6][0]) ? 6 : 5;
grid_put_schar(grid, irow+adj[0], i+adj[3], chars[ic], attrs[ic]); grid_put_schar(grid, irow+adj[0], i+adj[3], chars[ic], attrs[ic]);
} }
grid_put_schar(grid, irow+adj[0], icol+adj[3], chars[4], attrs[4]); if (adj[1]) {
grid_put_schar(grid, irow+adj[0], icol+adj[3], chars[4], attrs[4]);
}
grid_puts_line_flush(false); grid_puts_line_flush(false);
} }
} }

View File

@@ -723,8 +723,11 @@ void win_config_float(win_T *wp, FloatConfig fconfig)
bool has_border = wp->w_floating && wp->w_float_config.border; bool has_border = wp->w_floating && wp->w_float_config.border;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
wp->w_border_adj[i] = int new_adj = has_border && wp->w_float_config.border_chars[2 * i + 1][0];
has_border && wp->w_float_config.border_chars[2 * i+1][0]; if (new_adj != wp->w_border_adj[i]) {
change_border = true;
wp->w_border_adj[i] = new_adj;
}
} }
if (!ui_has(kUIMultigrid)) { if (!ui_has(kUIMultigrid)) {

View File

@@ -1194,6 +1194,49 @@ describe('float window', function()
]]} ]]}
end end
meths.win_set_config(win, {border={"", "_", "", "", "", "-", "", ""}})
if multigrid then
screen:expect{grid=[[
## grid 1
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[2:----------------------------------------]|
[3:----------------------------------------]|
## grid 2
^ |
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
{0:~ }|
## grid 3
|
## grid 5
{5:_________}|
{1: halloj! }|
{1: BORDAA }|
{5:---------}|
]], float_pos={
[5] = { { id = 1002 }, "NW", 1, 2, 5, true }
}, win_viewport={
[2] = {win = {id = 1000}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 1};
[5] = {win = {id = 1002}, topline = 0, botline = 2, curline = 0, curcol = 0, linecount = 2};
}}
else
screen:expect{grid=[[
^ |
{0:~ }|
{0:~ }{5:_________}{0: }|
{0:~ }{1: halloj! }{0: }|
{0:~ }{1: BORDAA }{0: }|
{0:~ }{5:---------}{0: }|
|
]]}
end
insert [[ insert [[
neeed some dummy neeed some dummy
background text background text