]> granicus.if.org Git - vim/commitdiff
patch 8.2.1854: Vim9: crash when throwing exception for NULL string v8.2.1854
authorBram Moolenaar <Bram@vim.org>
Fri, 16 Oct 2020 18:25:23 +0000 (20:25 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 16 Oct 2020 18:25:23 +0000 (20:25 +0200)
Problem:    Vim9: crash when throwing exception for NULL string. (Dhiraj
            Mishra)
Solution:   Handle NULL string like empty string. (closes #7139)

src/errors.h
src/testdir/test_vim9_script.vim
src/version.c
src/vim9execute.c

index c2dc633f161d9271a6559fd5268780b41d603660..7bacbd5317267803f15815ddc883ea01fde9d280 100644 (file)
@@ -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
index 43c66cc40f4b03ae52a6a50f15a50667951c5a99..9a2a481586510ebeeda10ec929b83b1b8fb435f1 100644 (file)
@@ -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()
index 5aa3cf669880d3f3e77d4b0aeca93888d0076446..4710689b691292224794137ce065b1fd64fd9d75 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1854,
 /**/
     1853,
 /**/
index 5c6dbdfab84259eb66b4e98eba7c03af3dc59ab4..521f1c9c0cd052b55b4e0ce97ac8091592a2e5cc 100644 (file)
@@ -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);