aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api/buffer_spec.lua
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-08-06 06:22:01 +0800
committerGitHub <noreply@github.com>2022-08-06 06:22:01 +0800
commita308f53525d77e26c372af385f6f4d89638b3962 (patch)
treef7909deca0a9b3f9aaa8e39d2b132186a502bfc0 /test/functional/api/buffer_spec.lua
parent85ad0e6b43b7890f11d8456f5396dcd7b69863b5 (diff)
downloadrneovim-a308f53525d77e26c372af385f6f4d89638b3962.tar.gz
rneovim-a308f53525d77e26c372af385f6f4d89638b3962.tar.bz2
rneovim-a308f53525d77e26c372af385f6f4d89638b3962.zip
fix(api): fix nvim_buf_set_text heap-use-after-free (#19644)
The line returned but ml_get_buf() may be freed by another call to ml_get_buf(), so it is necessary to make a copy.
Diffstat (limited to 'test/functional/api/buffer_spec.lua')
-rw-r--r--test/functional/api/buffer_spec.lua12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua
index dc668e7201..8f6fc666c9 100644
--- a/test/functional/api/buffer_spec.lua
+++ b/test/functional/api/buffer_spec.lua
@@ -7,6 +7,7 @@ local meths = helpers.meths
local funcs = helpers.funcs
local request = helpers.request
local exc_exec = helpers.exc_exec
+local exec_lua = helpers.exec_lua
local feed_command = helpers.feed_command
local insert = helpers.insert
local NIL = helpers.NIL
@@ -565,6 +566,17 @@ describe('api/buf', function()
eq('start is higher than end', pcall_err(set_text, 1, 0, 0, 0, {}))
eq('start is higher than end', pcall_err(set_text, 0, 1, 0, 0, {}))
end)
+
+ it('no heap-use-after-free when called consecutively #19643', function()
+ set_text(0, 0, 0, 0, {'one', '', '', 'two'})
+ eq({'one', '', '', 'two'}, get_lines(0, 4, true))
+ meths.win_set_cursor(0, {1, 0})
+ exec_lua([[
+ vim.api.nvim_buf_set_text(0, 0, 3, 1, 0, {''})
+ vim.api.nvim_buf_set_text(0, 0, 3, 1, 0, {''})
+ ]])
+ eq({'one', 'two'}, get_lines(0, 2, true))
+ end)
end)
describe('nvim_buf_get_text', function()