summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-04-25 15:24:44 +0200
committerBram Moolenaar <Bram@vim.org>2020-04-25 15:24:44 +0200
commit92b83ccfda7a1d654ccaaf161a9c8a8e01fbcf76 (patch)
tree92daff824edb3982d06e20aa33e3b2c8fe3331ed
parent9d8d0b5c644ea53364d04403740b3f23e57c1497 (diff)
downloadvim-git-92b83ccfda7a1d654ccaaf161a9c8a8e01fbcf76.tar.gz
patch 8.2.0634: crash with null partial and blobv8.2.0634
Problem: Crash with null partial and blob. Solution: Check for NULL pointer. Add more tests. (Yegappan Lakshmanan, closes #5984)
-rw-r--r--src/eval.c4
-rw-r--r--src/list.c3
-rw-r--r--src/testdir/test_blob.vim6
-rw-r--r--src/testdir/test_bufwintabinfo.vim1
-rw-r--r--src/testdir/test_cd.vim1
-rw-r--r--src/testdir/test_channel.vim4
-rw-r--r--src/testdir/test_cursor_func.vim1
-rw-r--r--src/testdir/test_eval_stuff.vim4
-rw-r--r--src/testdir/test_expr.vim3
-rw-r--r--src/testdir/test_filter_map.vim2
-rw-r--r--src/testdir/test_fnamemodify.vim4
-rw-r--r--src/testdir/test_functions.vim34
-rw-r--r--src/testdir/test_getvar.vim5
-rw-r--r--src/testdir/test_listdict.vim36
-rw-r--r--src/testdir/test_messages.vim3
-rw-r--r--src/testdir/test_partial.vim2
-rw-r--r--src/testdir/test_quickfix.vim12
-rw-r--r--src/testdir/test_tabpage.vim2
-rw-r--r--src/testdir/test_vimscript.vim12
-rw-r--r--src/version.c2
20 files changed, 136 insertions, 5 deletions
diff --git a/src/eval.c b/src/eval.c
index 659588f1d..4bd45e9ce 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -3682,7 +3682,9 @@ 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 (char_u *)"";
}
static void
diff --git a/src/list.c b/src/list.c
index dfd370b54..eb76cc683 100644
--- a/src/list.c
+++ b/src/list.c
@@ -2167,6 +2167,9 @@ f_insert(typval_T *argvars, typval_T *rettv)
int val, len;
char_u *p;
+ if (argvars[0].vval.v_blob == NULL)
+ return;
+
len = blob_len(argvars[0].vval.v_blob);
if (argvars[2].v_type != VAR_UNKNOWN)
{
diff --git a/src/testdir/test_blob.vim b/src/testdir/test_blob.vim
index 3c1510136..46b7b0227 100644
--- a/src/testdir/test_blob.vim
+++ b/src/testdir/test_blob.vim
@@ -33,6 +33,7 @@ func Test_blob_create()
call assert_fails('let b = 0z.')
call assert_fails('let b = 0z001122.')
call assert_fails('call get("", 1)', 'E896:')
+ call assert_equal(0, len(test_null_blob()))
endfunc
" assignment to a blob
@@ -100,6 +101,7 @@ func Test_blob_get()
call assert_equal(999, get(b, 5, 999))
call assert_equal(-1, get(b, -8))
call assert_equal(999, get(b, -8, 999))
+ call assert_equal(10, get(test_null_blob(), 2, 10))
call assert_equal(0x00, b[0])
call assert_equal(0x22, b[2])
@@ -117,6 +119,7 @@ func Test_blob_to_string()
call assert_equal('0z00112233', string(b))
call remove(b, 0, 3)
call assert_equal('0z', string(b))
+ call assert_equal('0z', string(test_null_blob()))
endfunc
func Test_blob_compare()
@@ -251,6 +254,7 @@ func Test_blob_func_remove()
call assert_fails("call remove(b, 3, 2)", 'E979:')
call assert_fails("call remove(1, 0)", 'E896:')
call assert_fails("call remove(b, b)", 'E974:')
+ call assert_fails("call remove(test_null_blob(), 1, 2)", 'E979:')
endfunc
func Test_blob_read_write()
@@ -313,6 +317,7 @@ func Test_blob_insert()
call assert_fails('call insert(b, 0, -20)', 'E475:')
call assert_fails('call insert(b, 0, 20)', 'E475:')
call assert_fails('call insert(b, [])', 'E745:')
+ call assert_equal(0, insert(test_null_blob(), 0x33))
endfunc
func Test_blob_reverse()
@@ -320,6 +325,7 @@ func Test_blob_reverse()
call assert_equal(0zBEADDE, reverse(0zDEADBE))
call assert_equal(0zADDE, reverse(0zDEAD))
call assert_equal(0zDE, reverse(0zDE))
+ call assert_equal(0z, reverse(test_null_blob()))
endfunc
func Test_blob_json_encode()
diff --git a/src/testdir/test_bufwintabinfo.vim b/src/testdir/test_bufwintabinfo.vim
index d61670b67..43d0473a1 100644
--- a/src/testdir/test_bufwintabinfo.vim
+++ b/src/testdir/test_bufwintabinfo.vim
@@ -42,6 +42,7 @@ func Test_getbufwintabinfo()
sign undefine Mark
enew!
endif
+ call assert_notequal([], getbufinfo(test_null_dict()))
only
let w1_id = win_getid()
diff --git a/src/testdir/test_cd.vim b/src/testdir/test_cd.vim
index e5c119e22..da9ef0830 100644
--- a/src/testdir/test_cd.vim
+++ b/src/testdir/test_cd.vim
@@ -119,6 +119,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/src/testdir/test_channel.vim b/src/testdir/test_channel.vim
index 9c51c640d..4ba552bdb 100644
--- a/src/testdir/test_channel.vim
+++ b/src/testdir/test_channel.vim
@@ -1139,6 +1139,8 @@ func Test_pipe_null()
call assert_equal("run", job_status(job))
call assert_equal('channel fail', string(job_getchannel(job)))
call assert_equal('fail', ch_status(job))
+ call assert_equal('no process', string(test_null_job()))
+ call assert_equal('channel fail', string(test_null_channel()))
call job_stop(job)
endfunc
@@ -1706,6 +1708,7 @@ func Test_partial_in_channel_cycle()
let d.a = function('string', [d])
try
let d.b = ch_open('nowhere:123', {'close_cb': d.a})
+ call test_garbagecollect_now()
catch
call assert_exception('E901:')
endtry
@@ -1893,6 +1896,7 @@ function Ch_test_close_lambda(port)
endif
let g:Ch_close_ret = ''
call ch_setoptions(handle, {'close_cb': {ch -> execute("let g:Ch_close_ret = 'closed'")}})
+ call test_garbagecollect_now()
call assert_equal('', ch_evalexpr(handle, 'close me'))
call WaitForAssert({-> assert_equal('closed', g:Ch_close_ret)})
diff --git a/src/testdir/test_cursor_func.vim b/src/testdir/test_cursor_func.vim
index 7a1795833..0ddfcdadf 100644
--- a/src/testdir/test_cursor_func.vim
+++ b/src/testdir/test_cursor_func.vim
@@ -2,6 +2,7 @@
func Test_wrong_arguments()
call assert_fails('call cursor(1. 3)', 'E474:')
+ call assert_fails('call cursor(test_null_list())', 'E474:')
endfunc
func Test_move_cursor()
diff --git a/src/testdir/test_eval_stuff.vim b/src/testdir/test_eval_stuff.vim
index cd9611c46..28350bb3e 100644
--- a/src/testdir/test_eval_stuff.vim
+++ b/src/testdir/test_eval_stuff.vim
@@ -41,6 +41,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(test_null_string()))
+ call assert_fails('call mkdir([])', 'E730')
+ call assert_fails('call mkdir("abc", [], [])', 'E745')
endfunc
func Test_line_continuation()
@@ -223,6 +226,7 @@ func Test_execute_cmd_with_null()
call assert_fails('execute test_null_blob()', 'E976:')
execute test_null_string()
call assert_fails('execute test_null_partial()', 'E729:')
+ 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/src/testdir/test_expr.vim b/src/testdir/test_expr.vim
index c8b5464f4..5fc502df8 100644
--- a/src/testdir/test_expr.vim
+++ b/src/testdir/test_expr.vim
@@ -24,6 +24,7 @@ func Test_equal()
call assert_fails('echo base.method > instance.method')
call assert_equal(0, test_null_function() == function('min'))
call assert_equal(1, test_null_function() == test_null_function())
+ call assert_fails('eval 10 == test_unknown()', 'E685:')
endfunc
func Test_version()
@@ -100,7 +101,7 @@ func Test_loop_over_null_list()
endfor
endfunc
-func Test_set_reg_null_list()
+func Test_setreg_null_list()
call setreg('x', test_null_list())
endfunc
diff --git a/src/testdir/test_filter_map.vim b/src/testdir/test_filter_map.vim
index 0e47badc2..0f58685c6 100644
--- a/src/testdir/test_filter_map.vim
+++ b/src/testdir/test_filter_map.vim
@@ -97,6 +97,8 @@ func Test_map_filter_fails()
call assert_fails("let l = filter([1, 2, 3], '{}')", 'E728:')
call assert_fails("let l = filter({'k' : 10}, '{}')", 'E728:')
call assert_fails("let l = filter([1, 2], {})", 'E731:')
+ call assert_equal(0, filter(test_null_list(), 0))
+ call assert_equal(0, filter(test_null_dict(), 0))
call assert_equal(0, map(test_null_list(), '"> " .. v:val'))
call assert_equal(0, map(test_null_dict(), '"> " .. v:val'))
call assert_equal([1, 2, 3], filter([1, 2, 3], test_null_function()))
diff --git a/src/testdir/test_fnamemodify.vim b/src/testdir/test_fnamemodify.vim
index b35f15340..b90d232f9 100644
--- a/src/testdir/test_fnamemodify.vim
+++ b/src/testdir/test_fnamemodify.vim
@@ -86,4 +86,8 @@ func Test_fnamemodify_er()
" :e never includes the whole filename, so "a.b":e:e:e --> "b"
call assert_equal('b.c', fnamemodify('a.b.c.d.e', ':r:r:e:e:e'))
call assert_equal('b.c', fnamemodify('a.b.c.d.e', ':r:r:e:e:e:e'))
+
+ call assert_equal('', fnamemodify(test_null_string(), test_null_string()))
endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim
index 029ea5b97..a0807ade7 100644
--- a/src/testdir/test_functions.vim
+++ b/src/testdir/test_functions.vim
@@ -480,6 +480,7 @@ func Test_pathshorten()
call assert_equal('~.f/bar', pathshorten('~.foo/bar'))
call assert_equal('.~f/bar', pathshorten('.~foo/bar'))
call assert_equal('~/f/bar', pathshorten('~/foo/bar'))
+ call assert_fails('call pathshorten([])', 'E730:')
endfunc
func Test_strpart()
@@ -970,6 +971,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(test_null_list(), '\a'))
endfunc
func Test_nextnonblank_prevnonblank()
@@ -1222,6 +1224,7 @@ func Test_hlexists()
syntax off
endfunc
+" Test for the col() function
func Test_col()
new
call setline(1, 'abcdef')
@@ -1332,6 +1335,7 @@ func Test_inputlist()
call assert_equal(-2, c)
call assert_fails('call inputlist("")', 'E686:')
+ call assert_fails('call inputlist(test_null_list())', 'E686:')
endfunc
func Test_balloon_show()
@@ -2227,6 +2231,16 @@ func Test_echoraw()
call delete('XTest_echoraw')
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:')
@@ -2258,7 +2272,27 @@ func Test_getcurpos_setpos()
call setpos('.', sp)
normal jyl
call assert_equal('6', @")
+ call assert_equal(-1, setpos('.', test_null_list()))
+ call assert_equal(-1, setpos('.', {}))
close!
endfunc
+" Test for glob()
+func Test_glob()
+ call assert_equal('', glob(test_null_string()))
+ call assert_equal('', globpath(test_null_string(), test_null_string()))
+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
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/testdir/test_getvar.vim b/src/testdir/test_getvar.vim
index 5da599136..7ced44d07 100644
--- a/src/testdir/test_getvar.vim
+++ b/src/testdir/test_getvar.vim
@@ -142,6 +142,11 @@ 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'))
+ 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/src/testdir/test_listdict.vim b/src/testdir/test_listdict.vim
index 87d7a2c94..1dea4a88c 100644
--- a/src/testdir/test_listdict.vim
+++ b/src/testdir/test_listdict.vim
@@ -724,6 +724,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
@@ -926,6 +927,8 @@ 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:')
+ let t = test_unknown()
+ call assert_fails("echo t[0]", 'E685:')
endfunc
" Test for a null list
@@ -943,7 +946,23 @@ func Test_null_list()
call assert_equal(0, uniq(l))
call assert_fails("let k = [] + l", 'E15:')
call assert_fails("let k = l + []", 'E15:')
- call assert_equal(0, len(copy(test_null_list())))
+ call assert_equal(0, len(copy(l)))
+ call assert_equal(0, count(l, 5))
+ call assert_equal([], deepcopy(l))
+ call assert_equal(5, get(l, 2, 5))
+ call assert_equal(-1, index(l, 2, 5))
+ call assert_equal(0, insert(l, 2, -1))
+ call assert_equal(0, min(l))
+ call assert_equal(0, max(l))
+ call assert_equal(0, remove(l, 0, 2))
+ call assert_equal([], repeat(l, 2))
+ call assert_equal(0, reverse(l))
+ call assert_equal(0, sort(l))
+ call assert_equal('[]', string(l))
+ call assert_equal(0, extend(l, l, 0))
+ lockvar l
+ call assert_equal(1, islocked('l'))
+ unlockvar l
endfunc
" Test for a null dict
@@ -958,9 +977,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 = test_null_dict()[10]')
+ call assert_fails('let x = d[10]')
call assert_equal({}, {})
- call assert_equal(0, len(copy(test_null_dict())))
+ 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
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/testdir/test_messages.vim b/src/testdir/test_messages.vim
index ac91aa097..84808efa0 100644
--- a/src/testdir/test_messages.vim
+++ b/src/testdir/test_messages.vim
@@ -305,9 +305,12 @@ func Test_null()
echom test_null_dict()
echom test_null_blob()
echom test_null_string()
+ echom test_null_function()
echom test_null_partial()
if has('job')
echom test_null_job()
echom test_null_channel()
endif
endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/testdir/test_partial.vim b/src/testdir/test_partial.vim
index 5b273db23..2fad7b289 100644
--- a/src/testdir/test_partial.vim
+++ b/src/testdir/test_partial.vim
@@ -194,6 +194,8 @@ 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))
+ call assert_equal("function('')", string(test_null_function()))
+ call assert_equal("function('')", string(test_null_partial()))
endfunc
func Test_func_unref()
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
index c1b50631b..cfd9a35b7 100644
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -2158,6 +2158,18 @@ func Xproperty_tests(cchar)
call g:Xsetlist([], 'a', {'context':246})
let d = g:Xgetlist({'context':1})
call assert_equal(246, d.context)
+ " set other Vim data types as context
+ call g:Xsetlist([], 'a', {'context' : test_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
+ call g:Xsetlist([], 'a', {'context' : test_null_function()})
+ call g:Xsetlist([], 'a', {'context' : test_null_partial()})
+ call g:Xsetlist([], 'a', {'context' : ''})
+ call test_garbagecollect_now()
if a:cchar == 'l'
" Test for copying context across two different location lists
new | only
diff --git a/src/testdir/test_tabpage.vim b/src/testdir/test_tabpage.vim
index 35c9fd0ea..80cc8e559 100644
--- a/src/testdir/test_tabpage.vim
+++ b/src/testdir/test_tabpage.vim
@@ -130,6 +130,8 @@ function Test_tabpage()
1tabmove
call assert_equal(2, tabpagenr())
+ call assert_fails('let t = tabpagenr("#")', 'E15:')
+ call assert_equal(0, tabpagewinnr(-1))
call assert_fails("99tabmove", 'E16:')
call assert_fails("+99tabmove", 'E16:')
call assert_fails("-99tabmove", 'E16:')
diff --git a/src/testdir/test_vimscript.vim b/src/testdir/test_vimscript.vim
index 439114d19..805787a7a 100644
--- a/src/testdir/test_vimscript.vim
+++ b/src/testdir/test_vimscript.vim
@@ -1164,6 +1164,18 @@ func Test_type()
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(test_null_string()))
+ call assert_equal(v:t_func, type(test_null_function()))
+ call assert_equal(v:t_func, type(test_null_partial()))
+ call assert_equal(v:t_list, type(test_null_list()))
+ call assert_equal(v:t_dict, type(test_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(test_null_blob()))
call assert_fails("call type(test_void())", 'E685:')
call assert_fails("call type(test_unknown())", 'E685:')
diff --git a/src/version.c b/src/version.c
index 81f5a3389..b05d3d884 100644
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 634,
+/**/
633,
/**/
632,