mirror of
https://github.com/neovim/neovim.git
synced 2025-09-25 20:48:32 +00:00
API: fix nvim_command_output buffer overflow (#10830)
Fixes https://github.com/neovim/neovim/issues/10829.
This commit is contained in:

committed by
Daniel Hahler

parent
ed28668392
commit
c6eb1f42be
@@ -364,7 +364,7 @@ String nvim_command_output(String command, Error *err)
|
|||||||
};
|
};
|
||||||
// redir usually (except :echon) prepends a newline.
|
// redir usually (except :echon) prepends a newline.
|
||||||
if (s.data[0] == '\n') {
|
if (s.data[0] == '\n') {
|
||||||
memmove(s.data, s.data + 1, s.size);
|
memmove(s.data, s.data + 1, s.size - 1);
|
||||||
s.data[s.size - 1] = '\0';
|
s.data[s.size - 1] = '\0';
|
||||||
s.size = s.size - 1;
|
s.size = s.size - 1;
|
||||||
}
|
}
|
||||||
|
@@ -178,6 +178,11 @@ describe('API', function()
|
|||||||
-- Verify NO hit-enter prompt.
|
-- Verify NO hit-enter prompt.
|
||||||
eq({mode='n', blocking=false}, nvim("get_mode"))
|
eq({mode='n', blocking=false}, nvim("get_mode"))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('Does not cause heap buffer overflow with large output', function()
|
||||||
|
eq(eval('string(range(1000000))'),
|
||||||
|
nvim('command_output', 'echo range(1000000)'))
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('nvim_eval', function()
|
describe('nvim_eval', function()
|
||||||
|
Reference in New Issue
Block a user