changeset 30136:5380551172aa v9.0.0404

patch 9.0.0404: crash when passing invalid arguments to assert_fails() Commit: https://github.com/vim/vim/commit/1540d334a04d874c2aa9d26b82dbbcd4bc5a78de Author: Bram Moolenaar <Bram@vim.org> Date: Wed Sep 7 15:20:26 2022 +0100 patch 9.0.0404: crash when passing invalid arguments to assert_fails() Problem: Crash when passing invalid arguments to assert_fails(). Solution: Check for NULL string.
author Bram Moolenaar <Bram@vim.org>
date Wed, 07 Sep 2022 16:30:02 +0200
parents e791a968eae1
children a207126c5111
files src/testdir/test_assert.vim src/testing.c src/version.c
diffstat 3 files changed, 28 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_assert.vim
+++ b/src/testdir/test_assert.vim
@@ -276,6 +276,21 @@ func Test_assert_fail_fails()
   call assert_match("E1222: String or List required for argument 2", exp)
 
   try
+    call assert_equal(0, assert_fails('xxx', [#{one: 1}]))
+  catch
+    let exp = v:exception
+  endtry
+  call assert_match("E731: Using a Dictionary as a String", exp)
+
+  let exp = ''
+  try
+    call assert_equal(0, assert_fails('xxx', ['E492', #{one: 1}]))
+  catch
+    let exp = v:exception
+  endtry
+  call assert_match("E731: Using a Dictionary as a String", exp)
+
+  try
     call assert_equal(1, assert_fails('xxx', 'E492', '', 'burp'))
   catch
     let exp = v:exception
@@ -289,8 +304,8 @@ func Test_assert_fail_fails()
   endtry
   call assert_match("E1174: String required for argument 5", exp)
 
-  call assert_equal(1, assert_fails('c0', ['', '\1']))
-  call assert_match("Expected '\\\\\\\\1' but got 'E939: Positive count required: c0': c0", v:errors[0])
+  call assert_equal(1, assert_fails('c0', ['', '\(.\)\1']))
+  call assert_match("Expected '\\\\\\\\(.\\\\\\\\)\\\\\\\\1' but got 'E939: Positive count required: c0': c0", v:errors[0])
   call remove(v:errors, 0)
 endfunc
 
--- a/src/testing.c
+++ b/src/testing.c
@@ -616,6 +616,11 @@ f_assert_fails(typval_T *argvars, typval
     in_assert_fails = TRUE;
 
     do_cmdline_cmd(cmd);
+
+    // reset here for any errors reported below
+    trylevel = save_trylevel;
+    suppress_errthrow = FALSE;
+
     if (called_emsg == called_emsg_before)
     {
 	prepare_assert_error(&ga);
@@ -654,6 +659,8 @@ f_assert_fails(typval_T *argvars, typval
 	    CHECK_LIST_MATERIALIZE(list);
 	    tv = &list->lv_first->li_tv;
 	    expected = tv_get_string_buf_chk(tv, buf);
+	    if (expected == NULL)
+		goto theend;
 	    if (!pattern_match(expected, actual, FALSE))
 	    {
 		error_found = TRUE;
@@ -667,6 +674,8 @@ f_assert_fails(typval_T *argvars, typval
 		{
 		    tv = &list->lv_u.mat.lv_last->li_tv;
 		    expected = tv_get_string_buf_chk(tv, buf);
+		    if (expected == NULL)
+			goto theend;
 		    if (!pattern_match(expected, actual, FALSE))
 		    {
 			error_found = TRUE;
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    404,
+/**/
     403,
 /**/
     402,