1
0
forked from aniani/vim

patch 9.0.0877: using freed memory with :comclear while listing commands

Problem:    Using freed memory with :comclear while listing commands.
Solution:   Bail out when the command list has changed. (closes #11440)
This commit is contained in:
Bram Moolenaar
2022-11-13 23:30:06 +00:00
parent 68353e5270
commit cf2594fbf3
4 changed files with 72 additions and 1 deletions

View File

@@ -2,6 +2,9 @@
import './vim9.vim' as v9
source check.vim
source screendump.vim
" Test for <mods> in user defined commands
function Test_cmdmods()
let g:mods = ''
@@ -373,6 +376,14 @@ func Test_CmdCompletion()
call feedkeys(":com MyCmd chist\<Tab>\<C-B>\"\<CR>", 'tx')
call assert_equal("\"com MyCmd chistory", @:)
" delete the Check commands to avoid them showing up
call feedkeys(":com Check\<C-A>\<C-B>\"\<CR>", 'tx')
let cmds = substitute(@:, '"com ', '', '')->split()
for cmd in cmds
exe 'delcommand ' .. cmd
endfor
delcommand MissingFeature
command! DoCmd1 :
command! DoCmd2 :
call feedkeys(":com \<C-A>\<C-B>\"\<CR>", 'tx')
@@ -716,6 +727,7 @@ func Test_usercmd_with_block()
echo 'hello'
END
call v9.CheckScriptFailure(lines, 'E1026:')
delcommand DoesNotEnd
let lines =<< trim END
command HelloThere {
@@ -754,6 +766,7 @@ func Test_usercmd_with_block()
BadCommand
END
call v9.CheckScriptFailure(lines, 'E1128:')
delcommand BadCommand
endfunc
func Test_delcommand_buffer()
@@ -817,7 +830,7 @@ func Test_recursive_define()
call DefCmd('Command')
let name = 'Command'
while len(name) < 30
while len(name) <= 30
exe 'delcommand ' .. name
let name ..= 'x'
endwhile
@@ -882,5 +895,30 @@ func Test_block_declaration_legacy_script()
delcommand Rename
endfunc
func Test_comclear_while_listing()
call CheckRunVimInTerminal()
let lines =<< trim END
set nocompatible
comclear
for i in range(1, 999)
exe 'command ' .. 'Foo' .. i .. ' bar'
endfor
au CmdlineLeave : call timer_start(0, {-> execute('comclear')})
END
call writefile(lines, 'Xcommandclear', 'D')
let buf = RunVimInTerminal('-S Xcommandclear', {'rows': 10})
" this was using freed memory
call term_sendkeys(buf, ":command\<CR>")
call TermWait(buf, 50)
call term_sendkeys(buf, "j")
call TermWait(buf, 50)
call term_sendkeys(buf, "G")
call term_sendkeys(buf, "\<CR>")
call StopVimInTerminal(buf)
endfunc
" vim: shiftwidth=2 sts=2 expandtab