]> granicus.if.org Git - vim/commitdiff
patch 8.2.3083: crash when passing null string to charclass() v8.2.3083
authorChristian Brabandt <cb@256bit.org>
Fri, 2 Jul 2021 18:19:31 +0000 (20:19 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 2 Jul 2021 18:19:31 +0000 (20:19 +0200)
Problem:    Crash when passing null string to charclass().
Solution:   Bail out when string pointer is NULL. (Christian Brabandt,
            closes #8498, closes #8260)

src/mbyte.c
src/testdir/test_functions.vim
src/version.c

index 8ac15d38a915329f5c2b177361427c93eb0934f3..b2519ecbaa4ae2628fa57524bdd437d245e486fa 100644 (file)
@@ -5587,7 +5587,8 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
     void
 f_charclass(typval_T *argvars, typval_T *rettv UNUSED)
 {
-    if (check_for_string_arg(argvars, 0) == FAIL)
+    if (check_for_string_arg(argvars, 0) == FAIL
+           || argvars[0].vval.v_string == NULL)
        return;
     rettv->vval.v_number = mb_get_class(argvars[0].vval.v_string);
 }
index 23af53274dad71568536529de13837bb5cb442cb..3164ca2174896c34e27e23d277c3508064cb080f 100644 (file)
@@ -2169,6 +2169,8 @@ func Test_charclass()
   call assert_equal(1, charclass('.'))
   call assert_equal(2, charclass('x'))
   call assert_equal(3, charclass("\u203c"))
+  " this used to crash vim
+  call assert_equal(0, "xxx"[-1]->charclass())
 endfunc
 
 func Test_eventhandler()
index 532e747871b38c969da9ecf176fd7056be821586..540fa2b6c80aaf4ce208d7729b1f5eccbf6aafb7 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3083,
 /**/
     3082,
 /**/