forked from aniani/vim
patch 9.0.0213: using freed memory with error in assert argument
Problem: Using freed memory with error in assert argument. Solution: Make a copy of the error.
This commit is contained in:
@@ -291,6 +291,10 @@ func Test_assert_fail_fails()
|
|||||||
let exp = v:exception
|
let exp = v:exception
|
||||||
endtry
|
endtry
|
||||||
call assert_match("E1174: String required for argument 5", exp)
|
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
|
endfunc
|
||||||
|
|
||||||
func Test_assert_fails_in_try_block()
|
func Test_assert_fails_in_try_block()
|
||||||
|
@@ -597,6 +597,7 @@ f_assert_fails(typval_T *argvars, typval_T *rettv)
|
|||||||
int save_trylevel = trylevel;
|
int save_trylevel = trylevel;
|
||||||
int called_emsg_before = called_emsg;
|
int called_emsg_before = called_emsg;
|
||||||
char *wrong_arg_msg = NULL;
|
char *wrong_arg_msg = NULL;
|
||||||
|
char_u *tofree = NULL;
|
||||||
|
|
||||||
if (check_for_string_or_number_arg(argvars, 0) == FAIL
|
if (check_for_string_or_number_arg(argvars, 0) == FAIL
|
||||||
|| check_for_opt_string_or_list_arg(argvars, 1) == FAIL
|
|| check_for_opt_string_or_list_arg(argvars, 1) == FAIL
|
||||||
@@ -659,9 +660,12 @@ f_assert_fails(typval_T *argvars, typval_T *rettv)
|
|||||||
expected_str = expected;
|
expected_str = expected;
|
||||||
}
|
}
|
||||||
else if (list->lv_len == 2)
|
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;
|
tv = &list->lv_u.mat.lv_last->li_tv;
|
||||||
actual = get_vim_var_str(VV_ERRMSG);
|
|
||||||
expected = tv_get_string_buf_chk(tv, buf);
|
expected = tv_get_string_buf_chk(tv, buf);
|
||||||
if (!pattern_match(expected, actual, FALSE))
|
if (!pattern_match(expected, actual, FALSE))
|
||||||
{
|
{
|
||||||
@@ -670,6 +674,7 @@ f_assert_fails(typval_T *argvars, typval_T *rettv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wrong_arg_msg = e_assert_fails_second_arg;
|
wrong_arg_msg = e_assert_fails_second_arg;
|
||||||
@@ -749,6 +754,7 @@ theend:
|
|||||||
msg_scrolled = 0;
|
msg_scrolled = 0;
|
||||||
lines_left = Rows;
|
lines_left = Rows;
|
||||||
VIM_CLEAR(emsg_assert_fails_msg);
|
VIM_CLEAR(emsg_assert_fails_msg);
|
||||||
|
vim_free(tofree);
|
||||||
set_vim_var_string(VV_ERRMSG, NULL, 0);
|
set_vim_var_string(VV_ERRMSG, NULL, 0);
|
||||||
if (wrong_arg_msg != NULL)
|
if (wrong_arg_msg != NULL)
|
||||||
emsg(_(wrong_arg_msg));
|
emsg(_(wrong_arg_msg));
|
||||||
|
@@ -735,6 +735,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
213,
|
||||||
/**/
|
/**/
|
||||||
212,
|
212,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user