diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-04-15 13:31:30 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-04-15 13:48:30 +0800 |
commit | 85741677c86f7686e3597a310f8059608e7816fb (patch) | |
tree | 2d203ebcd6609c1db6c61cde4d43fccb7424f341 | |
parent | 4b49f312a05214d5d1974f7ac2702ffb407fc558 (diff) | |
download | rneovim-85741677c86f7686e3597a310f8059608e7816fb.tar.gz rneovim-85741677c86f7686e3597a310f8059608e7816fb.tar.bz2 rneovim-85741677c86f7686e3597a310f8059608e7816fb.zip |
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)
https://github.com/vim/vim/commit/92b83ccfda7a1d654ccaaf161a9c8a8e01fbcf76
Co-authored-by: Bram Moolenaar <Bram@vim.org>
-rw-r--r-- | src/nvim/eval.c | 5 | ||||
-rw-r--r-- | test/old/testdir/test_bufwintabinfo.vim | 1 | ||||
-rw-r--r-- | test/old/testdir/test_cd.vim | 1 | ||||
-rw-r--r-- | test/old/testdir/test_eval_stuff.vim | 5 | ||||
-rw-r--r-- | test/old/testdir/test_expr.vim | 4 | ||||
-rw-r--r-- | test/old/testdir/test_functions.vim | 26 | ||||
-rw-r--r-- | test/old/testdir/test_getvar.vim | 6 | ||||
-rw-r--r-- | test/old/testdir/test_listdict.vim | 17 | ||||
-rw-r--r-- | test/old/testdir/test_messages.vim | 2 | ||||
-rw-r--r-- | test/old/testdir/test_partial.vim | 4 | ||||
-rw-r--r-- | test/old/testdir/test_quickfix.vim | 10 | ||||
-rw-r--r-- | test/old/testdir/test_vimscript.vim | 8 |
12 files changed, 86 insertions, 3 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 46cd837a73..f555d973e4 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -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) diff --git a/test/old/testdir/test_bufwintabinfo.vim b/test/old/testdir/test_bufwintabinfo.vim index 326aefb731..63f4fe6bb0 100644 --- a/test/old/testdir/test_bufwintabinfo.vim +++ b/test/old/testdir/test_bufwintabinfo.vim @@ -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() diff --git a/test/old/testdir/test_cd.vim b/test/old/testdir/test_cd.vim index 2b37f2c7c0..cffba99451 100644 --- a/test/old/testdir/test_cd.vim +++ b/test/old/testdir/test_cd.vim @@ -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) diff --git a/test/old/testdir/test_eval_stuff.vim b/test/old/testdir/test_eval_stuff.vim index 6a7fb223e0..90e3942c4d 100644 --- a/test/old/testdir/test_eval_stuff.vim +++ b/test/old/testdir/test_eval_stuff.vim @@ -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:') diff --git a/test/old/testdir/test_expr.vim b/test/old/testdir/test_expr.vim index b8ef87d714..1a00a85b0f 100644 --- a/test/old/testdir/test_expr.vim +++ b/test/old/testdir/test_expr.vim @@ -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 diff --git a/test/old/testdir/test_functions.vim b/test/old/testdir/test_functions.vim index 4ed1187a19..94c7e20264 100644 --- a/test/old/testdir/test_functions.vim +++ b/test/old/testdir/test_functions.vim @@ -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 diff --git a/test/old/testdir/test_getvar.vim b/test/old/testdir/test_getvar.vim index e6b6341fce..331f3cfe8a 100644 --- a/test/old/testdir/test_getvar.vim +++ b/test/old/testdir/test_getvar.vim @@ -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 diff --git a/test/old/testdir/test_listdict.vim b/test/old/testdir/test_listdict.vim index dc4abc3a7e..ba95e2ea9a 100644 --- a/test/old/testdir/test_listdict.vim +++ b/test/old/testdir/test_listdict.vim @@ -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 diff --git a/test/old/testdir/test_messages.vim b/test/old/testdir/test_messages.vim index ff4cf2c386..a20571807b 100644 --- a/test/old/testdir/test_messages.vim +++ b/test/old/testdir/test_messages.vim @@ -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') diff --git a/test/old/testdir/test_partial.vim b/test/old/testdir/test_partial.vim index f813539d42..302bc22d93 100644 --- a/test/old/testdir/test_partial.vim +++ b/test/old/testdir/test_partial.vim @@ -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() diff --git a/test/old/testdir/test_quickfix.vim b/test/old/testdir/test_quickfix.vim index fedc486e62..838c4b1c15 100644 --- a/test/old/testdir/test_quickfix.vim +++ b/test/old/testdir/test_quickfix.vim @@ -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' diff --git a/test/old/testdir/test_vimscript.vim b/test/old/testdir/test_vimscript.vim index 5988d6ed71..b5578f7f68 100644 --- a/test/old/testdir/test_vimscript.vim +++ b/test/old/testdir/test_vimscript.vim @@ -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) |