changeset 24697:a6e43da449af v8.2.2887

patch 8.2.2887: crash when passing null string to fullcommand() Commit: https://github.com/vim/vim/commit/4c8e8c6e19b75d632b042aa0ba0a2ab769b2162e Author: Bram Moolenaar <Bram@vim.org> Date: Wed May 26 19:49:09 2021 +0200 patch 8.2.2887: crash when passing null string to fullcommand() Problem: Crash when passing null string to fullcommand(). Solution: Check for NULL pointer. (closes https://github.com/vim/vim/issues/8256)
author Bram Moolenaar <Bram@vim.org>
date Wed, 26 May 2021 20:00:07 +0200
parents dc0703c51aef
children 5eef2f4937e3
files src/ex_docmd.c src/testdir/test_cmdline.vim src/version.c
diffstat 3 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -3791,12 +3791,15 @@ f_fullcommand(typval_T *argvars, typval_
     char_u   *name = argvars[0].vval.v_string;
     char_u   *p;
 
-    while (name[0] != NUL && name[0] == ':')
+    rettv->v_type = VAR_STRING;
+    rettv->vval.v_string = NULL;
+    if (name == NULL)
+	return;
+
+    while (*name != NUL && *name == ':')
 	name++;
     name = skip_range(name, TRUE, NULL);
 
-    rettv->v_type = VAR_STRING;
-
     ea.cmd = (*name == '2' || *name == '3') ? name + 1 : name;
     ea.cmdidx = (cmdidx_T)0;
     p = find_ex_command(&ea, NULL, NULL, NULL);
--- a/src/testdir/test_cmdline.vim
+++ b/src/testdir/test_cmdline.vim
@@ -475,6 +475,7 @@ func Test_fullcommand()
   for [in, want] in items(tests)
     call assert_equal(want, fullcommand(in))
   endfor
+  call assert_equal('', fullcommand(test_null_string()))
 
   call assert_equal('syntax', 'syn'->fullcommand())
 endfunc
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2887,
+/**/
     2886,
 /**/
     2885,