changeset 28646:a2cf17d0d5da v8.2.4847

patch 8.2.4847: crash when using uninitialized function pointer Commit: https://github.com/vim/vim/commit/a5d3590505fc3e1deea990560d472baa563abed7 Author: LemonBoy <thatlemon@gmail.com> Date: Fri Apr 29 21:15:02 2022 +0100 patch 8.2.4847: crash when using uninitialized function pointer Problem: Crash when using uninitialized function pointer. Solution: Check for NULL pointer. (closes https://github.com/vim/vim/issues/10319, closes https://github.com/vim/vim/issues/10319)
author Bram Moolenaar <Bram@vim.org>
date Fri, 29 Apr 2022 22:30:03 +0200
parents a9eca6be0c8c
children 1c10b937eb03
files src/eval.c src/testdir/test_vim9_script.vim src/version.c
diffstat 3 files changed, 36 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/eval.c
+++ b/src/eval.c
@@ -5314,7 +5314,8 @@ echo_string_core(
 
 		if (echo_style)
 		{
-		    r = make_ufunc_name_readable(tv->vval.v_string,
+		    r = tv->vval.v_string == NULL ? (char_u *)"function()"
+				  : make_ufunc_name_readable(tv->vval.v_string,
 						       buf, MAX_FUNC_NAME_LEN);
 		    if (r == buf)
 		    {
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -4115,6 +4115,38 @@ def Run_Test_misplaced_type()
   delete('XTest_misplaced_type')
 enddef
 
+" Ensure echo doesn't crash when stringifying empty variables.
+def Test_echo_uninit_variables()
+  var res: string
+
+  var var_bool: bool
+  var var_num: number
+  var var_float: float
+  var Var_func: func
+  var var_string: string
+  var var_blob: blob
+  var var_job: job
+  var var_channel: channel
+  var var_list: list<any>
+  var var_dict: dict<any>
+
+  redir => res
+  echo var_bool
+  echo var_num
+  echo var_float
+  echo Var_func
+  echo var_string
+  echo var_blob
+  echo var_job
+  echo var_channel
+  echo var_list
+  echo var_dict
+  redir END
+
+  assert_equal(['false', '0', '0.0', 'function()', '', '0z', 'no process',
+    'channel fail', '[]', '{}'], res->split('\n'))
+enddef
+
 " Keep this last, it messes up highlighting.
 def Test_substitute_cmd()
   new
--- 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 */
 /**/
+    4847,
+/**/
     4846,
 /**/
     4845,