mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
vim-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.
1540d334a0
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -531,6 +531,11 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
|||||||
no_wait_return++;
|
no_wait_return++;
|
||||||
|
|
||||||
do_cmdline_cmd(cmd);
|
do_cmdline_cmd(cmd);
|
||||||
|
|
||||||
|
// reset here for any errors reported below
|
||||||
|
trylevel = save_trylevel;
|
||||||
|
suppress_errthrow = false;
|
||||||
|
|
||||||
if (called_emsg == called_emsg_before) {
|
if (called_emsg == called_emsg_before) {
|
||||||
prepare_assert_error(&ga);
|
prepare_assert_error(&ga);
|
||||||
ga_concat(&ga, "command did not fail: ");
|
ga_concat(&ga, "command did not fail: ");
|
||||||
@@ -557,6 +562,9 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
|||||||
}
|
}
|
||||||
const typval_T *tv = TV_LIST_ITEM_TV(tv_list_first(list));
|
const typval_T *tv = TV_LIST_ITEM_TV(tv_list_first(list));
|
||||||
expected = tv_get_string_buf_chk(tv, buf);
|
expected = tv_get_string_buf_chk(tv, buf);
|
||||||
|
if (expected == NULL) {
|
||||||
|
goto theend;
|
||||||
|
}
|
||||||
if (!pattern_match(expected, actual, false)) {
|
if (!pattern_match(expected, actual, false)) {
|
||||||
error_found = true;
|
error_found = true;
|
||||||
expected_str = expected;
|
expected_str = expected;
|
||||||
@@ -565,6 +573,9 @@ void f_assert_fails(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
|||||||
tofree = actual = xstrdup(get_vim_var_str(VV_ERRMSG));
|
tofree = actual = xstrdup(get_vim_var_str(VV_ERRMSG));
|
||||||
tv = TV_LIST_ITEM_TV(tv_list_last(list));
|
tv = TV_LIST_ITEM_TV(tv_list_last(list));
|
||||||
expected = tv_get_string_buf_chk(tv, buf);
|
expected = tv_get_string_buf_chk(tv, buf);
|
||||||
|
if (expected == NULL) {
|
||||||
|
goto theend;
|
||||||
|
}
|
||||||
if (!pattern_match(expected, actual, false)) {
|
if (!pattern_match(expected, actual, false)) {
|
||||||
error_found = true;
|
error_found = true;
|
||||||
expected_str = expected;
|
expected_str = expected;
|
||||||
|
@@ -264,6 +264,21 @@ func Test_assert_fail_fails()
|
|||||||
endtry
|
endtry
|
||||||
call assert_match("E1222: String or List required for argument 2", exp)
|
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
|
try
|
||||||
call assert_equal(1, assert_fails('xxx', 'E492', '', 'burp'))
|
call assert_equal(1, assert_fails('xxx', 'E492', '', 'burp'))
|
||||||
catch
|
catch
|
||||||
@@ -278,8 +293,8 @@ func Test_assert_fail_fails()
|
|||||||
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_equal(1, assert_fails('c0', ['', '\(.\)\1']))
|
||||||
call assert_match("Expected '\\\\\\\\1' but got 'E939: Positive count required: c0': c0", v:errors[0])
|
call assert_match("Expected '\\\\\\\\(.\\\\\\\\)\\\\\\\\1' but got 'E939: Positive count required: c0': c0", v:errors[0])
|
||||||
call remove(v:errors, 0)
|
call remove(v:errors, 0)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user