]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.0896: crash when calling searchcount() with a string v8.2.0896
authorBram Moolenaar <Bram@vim.org>
Wed, 3 Jun 2020 20:57:39 +0000 (22:57 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 3 Jun 2020 20:57:39 +0000 (22:57 +0200)
Problem:    Crash when calling searchcount() with a string.
Solution:   Check the argument is a dict. (closes #6192)

src/search.c
src/testdir/test_search_stat.vim
src/version.c

index 210806258f50d40c8d0a65ddaf8c94fe2648f5a2..7346383fc5c4e2f43d41fc18bbde129fd684eac6 100644 (file)
@@ -3175,7 +3175,7 @@ update_search_stat(
     int                    save_ws = p_ws;
     int                    wraparound = FALSE;
     pos_T          p = (*pos);
-    static  pos_T   lastpos = {0, 0, 0};
+    static pos_T    lastpos = {0, 0, 0};
     static int     cur = 0;
     static int     cnt = 0;
     static int     exact_match = FALSE;
@@ -4072,11 +4072,17 @@ f_searchcount(typval_T *argvars, typval_T *rettv)
 
     if (argvars[0].v_type != VAR_UNKNOWN)
     {
-       dict_T          *dict = argvars[0].vval.v_dict;
+       dict_T          *dict;
        dictitem_T      *di;
        listitem_T      *li;
        int             error = FALSE;
 
+       if (argvars[0].v_type != VAR_DICT || argvars[0].vval.v_dict == NULL)
+       {
+           emsg(_(e_dictreq));
+           return;
+       }
+       dict = argvars[0].vval.v_dict;
        di = dict_find(dict, (char_u *)"timeout", -1);
        if (di != NULL)
        {
index 668545c5a7a9090e310300328934346b63cdcd8a..85e4f866ef358470930cae39a871c2de8cdbee92 100644 (file)
@@ -259,6 +259,10 @@ func Test_search_stat()
   bwipe!
 endfunc
 
+func Test_searchcount_fails()
+  call assert_fails('echo searchcount("boo!")', 'E715:')
+endfunc
+
 func Test_search_stat_foldopen()
   CheckScreendump
 
index 801069bebef0a006e46ffa79fdeea3e66b4fd705..0f017124176d7884a9d3c8c6ece85be95703855c 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    896,
 /**/
     895,
 /**/