vim-patch:8.2.0634: crash with null partial and blob

Problem:    Crash with null partial and blob.
Solution:   Check for NULL pointer.  Add more tests. (Yegappan Lakshmanan,
            closes vim/vim#5984)

92b83ccfda

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq 2023-04-15 13:31:30 +08:00
parent 4b49f312a0
commit 85741677c8
12 changed files with 86 additions and 3 deletions

View File

@ -4059,7 +4059,10 @@ char *partial_name(partial_T *pt)
if (pt->pt_name != NULL) {
return pt->pt_name;
}
return pt->pt_func->uf_name;
if (pt->pt_func != NULL) {
return pt->pt_func->uf_name;
}
return "";
}
static void partial_free(partial_T *pt)

View File

@ -42,6 +42,7 @@ function Test_getbufwintabinfo()
sign undefine Mark
enew!
endif
call assert_notequal([], getbufinfo(v:_null_dict))
only
let w1_id = win_getid()

View File

@ -106,6 +106,7 @@ func Test_chdir_func()
call assert_equal("", d)
" Should not crash
call chdir(d)
call assert_equal('', chdir([]))
only | tabonly
call chdir(topdir)

View File

@ -39,6 +39,9 @@ func Test_mkdir_p()
call assert_fails('call mkdir("Xfile", "p")', 'E739')
call delete('Xfile')
call delete('Xmkdir', 'rf')
call assert_equal(0, mkdir(v:_null_string))
call assert_fails('call mkdir([])', 'E730')
call assert_fails('call mkdir("abc", [], [])', 'E745')
endfunc
func Test_line_continuation()
@ -212,6 +215,8 @@ func Test_execute_cmd_with_null()
execute v:_null_string
" Nvim doesn't have null partials
" call assert_fails('execute test_null_partial()', 'E729:')
" Nvim doesn't have test_unknown()
" call assert_fails('execute test_unknown()', 'E908:')
if has('job')
call assert_fails('execute test_null_job()', 'E908:')
call assert_fails('execute test_null_channel()', 'E908:')

View File

@ -25,6 +25,8 @@ func Test_equal()
" Nvim doesn't have null functions
" call assert_equal(0, test_null_function() == function('min'))
" call assert_equal(1, test_null_function() == test_null_function())
" Nvim doesn't have test_unknown()
" call assert_fails('eval 10 == test_unknown()', 'E685:')
endfunc
func Test_version()
@ -137,7 +139,7 @@ func Test_loop_over_null_list()
endfor
endfunc
func Test_set_reg_null_list()
func Test_setreg_null_list()
call setreg('x', v:_null_list)
endfunc

View File

@ -990,6 +990,7 @@ func Test_matchstrpos()
call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 8))
call assert_equal(['ing', 1, 4, 7], matchstrpos(['vim', 'testing', 'execute'], 'ing'))
call assert_equal(['', -1, -1, -1], matchstrpos(['vim', 'testing', 'execute'], 'img'))
call assert_equal(['', -1, -1], matchstrpos(v:_null_list, '\a'))
endfunc
func Test_nextnonblank_prevnonblank()
@ -1284,6 +1285,7 @@ func Test_hlexists()
syntax off
endfunc
" Test for the col() function
func Test_col()
new
call setline(1, 'abcdef')
@ -1435,6 +1437,8 @@ func Test_inputlist()
call assert_equal(-2, c)
call assert_fails('call inputlist("")', 'E686:')
" Nvim accepts null list as empty list
" call assert_fails('call inputlist(v:_null_list)', 'E686:')
endfunc
func Test_range_inputlist()
@ -2357,6 +2361,16 @@ func Test_garbagecollect_now_fails()
let v:testing = 1
endfunc
" Test for echo highlighting
func Test_echohl()
echohl Search
echo 'Vim'
call assert_equal('Vim', Screenline(&lines))
" TODO: How to check the highlight group used by echohl?
" ScreenAttrs() returns all zeros.
echohl None
endfunc
" Test for the eval() function
func Test_eval()
call assert_fails("call eval('5 a')", 'E488:')
@ -2515,6 +2529,18 @@ func Test_glob()
call assert_fails("call glob('*', 0, {})", 'E728:')
endfunc
" Test for browse()
func Test_browse()
CheckFeature browse
call assert_fails('call browse([], "open", "x", "a.c")', 'E745:')
endfunc
" Test for browsedir()
func Test_browsedir()
CheckFeature browse
call assert_fails('call browsedir("open", [])', 'E730:')
endfunc
func HasDefault(msg = 'msg')
return a:msg
endfunc

View File

@ -150,6 +150,12 @@ func Test_get_func()
call assert_equal({'func has': 'no dict'}, get(l:F, 'dict', {'func has': 'no dict'}))
call assert_equal(0, get(l:F, 'dict'))
call assert_equal([], get(l:F, 'args'))
" Nvim doesn't have null functions
" let NF = test_null_function()
" call assert_equal('', get(NF, 'name'))
" call assert_equal(NF, get(NF, 'func'))
" call assert_equal(0, get(NF, 'dict'))
" call assert_equal([], get(NF, 'args'))
endfunc
" get({partial}, {what} [, {default}]) - in test_partial.vim

View File

@ -794,6 +794,7 @@ func Test_listdict_compare_complex()
call assert_true(dict4 == dict4copy)
endfunc
" Test for extending lists and dictionaries
func Test_listdict_extend()
" Test extend() with lists
@ -1028,6 +1029,9 @@ func Test_listdict_index()
call assert_fails("let l[1.1] = 4", 'E806:')
call assert_fails("let l[:i] = [4, 5]", 'E121:')
call assert_fails("let l[:3.2] = [4, 5]", 'E806:')
" Nvim doesn't have test_unknown()
" let t = test_unknown()
" call assert_fails("echo t[0]", 'E685:')
endfunc
" Test for a null list
@ -1079,9 +1083,20 @@ func Test_null_dict()
call assert_equal(0, values(d))
call assert_false(has_key(d, 'k'))
call assert_equal('{}', string(d))
call assert_fails('let x = v:_null_dict[10]')
call assert_fails('let x = d[10]')
call assert_equal({}, {})
call assert_equal(0, len(copy(d)))
call assert_equal(0, count(d, 'k'))
call assert_equal({}, deepcopy(d))
call assert_equal(20, get(d, 'k', 20))
call assert_equal(0, min(d))
call assert_equal(0, max(d))
call assert_equal(0, remove(d, 'k'))
call assert_equal('{}', string(d))
" call assert_equal(0, extend(d, d, 0))
lockvar d
call assert_equal(1, islocked('d'))
unlockvar d
endfunc
" Test for the indexof() function

View File

@ -408,6 +408,8 @@ func Test_null()
echom v:_null_dict
echom v:_null_blob
echom v:_null_string
" Nvim doesn't have NULL functions
" echom test_null_function()
" Nvim doesn't have NULL partials
" echom test_null_partial()
if has('job')

View File

@ -194,6 +194,10 @@ func Test_partial_string()
call assert_equal("function('MyFunc', {'one': 1})", string(F))
let F = function('MyFunc', ['foo'], d)
call assert_equal("function('MyFunc', ['foo'], {'one': 1})", string(F))
" Nvim doesn't have null functions
" call assert_equal("function('')", string(test_null_function()))
" Nvim doesn't have null partials
" call assert_equal("function('')", string(test_null_partial()))
endfunc
func Test_func_unref()

View File

@ -2425,6 +2425,16 @@ func Xproperty_tests(cchar)
call assert_equal(246, d.context)
" set other Vim data types as context
call g:Xsetlist([], 'a', {'context' : v:_null_blob})
if has('channel')
call g:Xsetlist([], 'a', {'context' : test_null_channel()})
endif
if has('job')
call g:Xsetlist([], 'a', {'context' : test_null_job()})
endif
" Nvim doesn't have null functions
" call g:Xsetlist([], 'a', {'context' : test_null_function()})
" Nvim doesn't have null partials
" call g:Xsetlist([], 'a', {'context' : test_null_partial()})
call g:Xsetlist([], 'a', {'context' : ''})
call test_garbagecollect_now()
if a:cchar == 'l'

View File

@ -6508,9 +6508,17 @@ func Test_type()
call assert_equal(v:t_float, type(0.0))
call assert_equal(v:t_bool, type(v:false))
call assert_equal(v:t_bool, type(v:true))
" call assert_equal(v:t_none, type(v:none))
" call assert_equal(v:t_none, type(v:null))
call assert_equal(v:t_string, type(v:_null_string))
call assert_equal(v:t_list, type(v:_null_list))
call assert_equal(v:t_dict, type(v:_null_dict))
if has('job')
call assert_equal(v:t_job, type(test_null_job()))
endif
if has('channel')
call assert_equal(v:t_channel, type(test_null_channel()))
endif
call assert_equal(v:t_blob, type(v:_null_blob))
call assert_equal(0, 0 + v:false)