diff options
author | Christian Brabandt <cb@256bit.org> | 2021-07-02 20:19:31 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-07-02 20:19:31 +0200 |
commit | 72463f883cdfd08e29ab0018ef3889284848d5f1 (patch) | |
tree | 7ef8a34ac8ecb1457755772f3f6fca01378410dc | |
parent | b836f631dba2534efd314a8f77439cebc75acd4e (diff) |
patch 8.2.3083: crash when passing null string to charclass()v8.2.3083
Problem: Crash when passing null string to charclass().
Solution: Bail out when string pointer is NULL. (Christian Brabandt,
closes #8498, closes #8260)
-rw-r--r-- | src/mbyte.c | 3 | ||||
-rw-r--r-- | src/testdir/test_functions.vim | 2 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 6 insertions, 1 deletions
diff --git a/src/mbyte.c b/src/mbyte.c index 8ac15d38a9..b2519ecbaa 100644 --- a/src/mbyte.c +++ b/src/mbyte.c @@ -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); } diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim index 23af53274d..3164ca2174 100644 --- a/src/testdir/test_functions.vim +++ b/src/testdir/test_functions.vim @@ -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() diff --git a/src/version.c b/src/version.c index 532e747871..540fa2b6c8 100644 --- a/src/version.c +++ b/src/version.c @@ -756,6 +756,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3083, +/**/ 3082, /**/ 3081, |