summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-10-16 20:25:23 +0200
committerBram Moolenaar <Bram@vim.org>2020-10-16 20:25:23 +0200
commit1e021e63c565bbb30783a557b4e883cc27f56403 (patch)
tree0e0b4b4b39e9cd3bf76a91c86e3c5f9259fbea79
parent7a66a17190f2f64688a697ea29d58388612122ce (diff)
patch 8.2.1854: Vim9: crash when throwing exception for NULL stringv8.2.1854
Problem: Vim9: crash when throwing exception for NULL string. (Dhiraj Mishra) Solution: Handle NULL string like empty string. (closes #7139)
-rw-r--r--src/errors.h2
-rw-r--r--src/testdir/test_vim9_script.vim15
-rw-r--r--src/version.c2
-rw-r--r--src/vim9execute.c9
4 files changed, 28 insertions, 0 deletions
diff --git a/src/errors.h b/src/errors.h
index c2dc633f16..7bacbd5317 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -280,4 +280,6 @@ EXTERN char e_missing_name_after_dot[]
INIT(= N_("E1127: Missing name after dot"));
EXTERN char e_endblock_without_block[]
INIT(= N_("E1128: } without {"));
+EXTERN char e_throw_with_empty_string[]
+ INIT(= N_("E1129: Throw with empty string"));
#endif
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 43c66cc40f..9a2a481586 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -617,6 +617,21 @@ def Test_throw_vimscript()
endtry
END
CheckScriptSuccess(lines)
+
+ lines =<< trim END
+ vim9script
+ def Func()
+ throw @r
+ enddef
+ var result = ''
+ try
+ Func()
+ catch /E1129:/
+ result = 'caught'
+ endtry
+ assert_equal('caught', result)
+ END
+ CheckScriptSuccess(lines)
enddef
def Test_error_in_nested_function()
diff --git a/src/version.c b/src/version.c
index 5aa3cf6698..4710689b69 100644
--- 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 */
/**/
+ 1854,
+/**/
1853,
/**/
1852,
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 5c6dbdfab8..521f1c9c0c 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -1381,6 +1381,8 @@ call_def_function(
tv = STACK_TV_BOT(0);
tv->v_type = VAR_STRING;
tv->v_lock = 0;
+ // This may result in NULL, which should be equivalent to an
+ // empty string.
tv->vval.v_string = get_reg_contents(
iptr->isn_arg.number, GREG_EXPR_SRC);
++ectx.ec_stack.ga_len;
@@ -2082,6 +2084,13 @@ call_def_function(
case ISN_THROW:
--ectx.ec_stack.ga_len;
tv = STACK_TV_BOT(0);
+ if (tv->vval.v_string == NULL
+ || *skipwhite(tv->vval.v_string) == NUL)
+ {
+ emsg(_(e_throw_with_empty_string));
+ goto failed;
+ }
+
if (throw_exception(tv->vval.v_string, ET_USER, NULL) == FAIL)
{
vim_free(tv->vval.v_string);