mirror of
https://github.com/neovim/neovim
synced 2025-07-16 17:21:49 +00:00
fix(api): crash after nvim_win_set_config title/footer validation error (#26606)
This commit is contained in:
@ -431,18 +431,36 @@ static bool parse_float_bufpos(Array bufpos, lpos_T *out)
|
|||||||
static void parse_bordertext(Object bordertext, BorderTextType bordertext_type,
|
static void parse_bordertext(Object bordertext, BorderTextType bordertext_type,
|
||||||
FloatConfig *fconfig, Error *err)
|
FloatConfig *fconfig, Error *err)
|
||||||
{
|
{
|
||||||
|
if (bordertext.type != kObjectTypeString && bordertext.type != kObjectTypeArray) {
|
||||||
|
api_set_error(err, kErrorTypeValidation, "title/footer must be string or array");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bordertext.type == kObjectTypeArray && bordertext.data.array.size == 0) {
|
||||||
|
api_set_error(err, kErrorTypeValidation, "title/footer cannot be an empty array");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bool *is_present;
|
bool *is_present;
|
||||||
VirtText *chunks;
|
VirtText *chunks;
|
||||||
int *width;
|
int *width;
|
||||||
int default_hl_id;
|
int default_hl_id;
|
||||||
switch (bordertext_type) {
|
switch (bordertext_type) {
|
||||||
case kBorderTextTitle:
|
case kBorderTextTitle:
|
||||||
|
if (fconfig->title) {
|
||||||
|
clear_virttext(&fconfig->title_chunks);
|
||||||
|
}
|
||||||
|
|
||||||
is_present = &fconfig->title;
|
is_present = &fconfig->title;
|
||||||
chunks = &fconfig->title_chunks;
|
chunks = &fconfig->title_chunks;
|
||||||
width = &fconfig->title_width;
|
width = &fconfig->title_width;
|
||||||
default_hl_id = syn_check_group(S_LEN("FloatTitle"));
|
default_hl_id = syn_check_group(S_LEN("FloatTitle"));
|
||||||
break;
|
break;
|
||||||
case kBorderTextFooter:
|
case kBorderTextFooter:
|
||||||
|
if (fconfig->footer) {
|
||||||
|
clear_virttext(&fconfig->footer_chunks);
|
||||||
|
}
|
||||||
|
|
||||||
is_present = &fconfig->footer;
|
is_present = &fconfig->footer;
|
||||||
chunks = &fconfig->footer_chunks;
|
chunks = &fconfig->footer_chunks;
|
||||||
width = &fconfig->footer_width;
|
width = &fconfig->footer_width;
|
||||||
@ -462,16 +480,6 @@ static void parse_bordertext(Object bordertext, BorderTextType bordertext_type,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bordertext.type != kObjectTypeArray) {
|
|
||||||
api_set_error(err, kErrorTypeValidation, "title must be string or array");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bordertext.data.array.size == 0) {
|
|
||||||
api_set_error(err, kErrorTypeValidation, "title cannot be an empty array");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
*width = 0;
|
*width = 0;
|
||||||
*chunks = parse_virt_text(bordertext.data.array, err, width);
|
*chunks = parse_virt_text(bordertext.data.array, err, width);
|
||||||
|
|
||||||
@ -774,10 +782,6 @@ static bool parse_float_config(Dict(float_config) *config, FloatConfig *fconfig,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fconfig->title) {
|
|
||||||
clear_virttext(&fconfig->title_chunks);
|
|
||||||
}
|
|
||||||
|
|
||||||
parse_bordertext(config->title, kBorderTextTitle, fconfig, err);
|
parse_bordertext(config->title, kBorderTextTitle, fconfig, err);
|
||||||
if (ERROR_SET(err)) {
|
if (ERROR_SET(err)) {
|
||||||
return false;
|
return false;
|
||||||
@ -801,10 +805,6 @@ static bool parse_float_config(Dict(float_config) *config, FloatConfig *fconfig,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fconfig->footer) {
|
|
||||||
clear_virttext(&fconfig->footer_chunks);
|
|
||||||
}
|
|
||||||
|
|
||||||
parse_bordertext(config->footer, kBorderTextFooter, fconfig, err);
|
parse_bordertext(config->footer, kBorderTextFooter, fconfig, err);
|
||||||
if (ERROR_SET(err)) {
|
if (ERROR_SET(err)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -906,4 +906,38 @@ describe('API/win', function()
|
|||||||
eq(footer, cfg.footer)
|
eq(footer, cfg.footer)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('set_config', function()
|
||||||
|
it('no crash with invalid title', function ()
|
||||||
|
local win = meths.open_win(0, true, {
|
||||||
|
width = 10,
|
||||||
|
height = 10,
|
||||||
|
relative = "editor",
|
||||||
|
row = 10,
|
||||||
|
col = 10,
|
||||||
|
title = { { "test" } },
|
||||||
|
border = "single",
|
||||||
|
})
|
||||||
|
eq("title/footer cannot be an empty array",
|
||||||
|
pcall_err(meths.win_set_config, win, {title = {}}))
|
||||||
|
command("redraw!")
|
||||||
|
assert_alive()
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('no crash with invalid footer', function ()
|
||||||
|
local win = meths.open_win(0, true, {
|
||||||
|
width = 10,
|
||||||
|
height = 10,
|
||||||
|
relative = "editor",
|
||||||
|
row = 10,
|
||||||
|
col = 10,
|
||||||
|
footer = { { "test" } },
|
||||||
|
border = "single",
|
||||||
|
})
|
||||||
|
eq("title/footer cannot be an empty array",
|
||||||
|
pcall_err(meths.win_set_config, win, {footer = {}}))
|
||||||
|
command("redraw!")
|
||||||
|
assert_alive()
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user