Patch 9.0.0213

10 views
Skip to first unread message

Bram Moolenaar

unread,
Aug 14, 2022, 5:23:43 PM8/14/22
to vim...@googlegroups.com

Patch 9.0.0213
Problem: Using freed memory with error in assert argument.
Solution: Make a copy of the error.
Files: src/testing.c, src/testdir/test_assert.vim


*** ../vim-9.0.0212/src/testing.c 2022-07-23 09:52:00.341814264 +0100
--- src/testing.c 2022-08-14 22:21:01.798497130 +0100
***************
*** 597,602 ****
--- 597,603 ----
int save_trylevel = trylevel;
int called_emsg_before = called_emsg;
char *wrong_arg_msg = NULL;
+ char_u *tofree = NULL;

if (check_for_string_or_number_arg(argvars, 0) == FAIL
|| check_for_opt_string_or_list_arg(argvars, 1) == FAIL
***************
*** 660,672 ****
}
else if (list->lv_len == 2)
{
! tv = &list->lv_u.mat.lv_last->li_tv;
! actual = get_vim_var_str(VV_ERRMSG);
! expected = tv_get_string_buf_chk(tv, buf);
! if (!pattern_match(expected, actual, FALSE))
{
! error_found = TRUE;
! expected_str = expected;
}
}
}
--- 661,677 ----
}
else if (list->lv_len == 2)
{
! // make a copy, an error in pattern_match() may free it
! tofree = actual = vim_strsave(get_vim_var_str(VV_ERRMSG));
! if (actual != NULL)
{
! tv = &list->lv_u.mat.lv_last->li_tv;
! expected = tv_get_string_buf_chk(tv, buf);
! if (!pattern_match(expected, actual, FALSE))
! {
! error_found = TRUE;
! expected_str = expected;
! }
}
}
}
***************
*** 749,754 ****
--- 754,760 ----
msg_scrolled = 0;
lines_left = Rows;
VIM_CLEAR(emsg_assert_fails_msg);
+ vim_free(tofree);
set_vim_var_string(VV_ERRMSG, NULL, 0);
if (wrong_arg_msg != NULL)
emsg(_(wrong_arg_msg));
*** ../vim-9.0.0212/src/testdir/test_assert.vim 2022-02-16 12:13:17.000000000 +0000
--- src/testdir/test_assert.vim 2022-08-14 22:19:21.630326863 +0100
***************
*** 291,296 ****
--- 291,300 ----
let exp = v:exception
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 remove(v:errors, 0)
endfunc

func Test_assert_fails_in_try_block()
*** ../vim-9.0.0212/src/version.c 2022-08-14 21:46:03.686021093 +0100
--- src/version.c 2022-08-14 22:04:55.767776495 +0100
***************
*** 737,738 ****
--- 737,740 ----
{ /* Add new patch number below this line */
+ /**/
+ 213,
/**/

--
Veni, Vidi, Video -- I came, I saw, I taped what I saw.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages