Skip to content

Commit 1540d33

Browse files
committed
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.
1 parent fd7e60a commit 1540d33

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/testdir/test_assert.vim

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,21 @@ func Test_assert_fail_fails()
275275
endtry
276276
call assert_match("E1222: String or List required for argument 2", exp)
277277

278+
try
279+
call assert_equal(0, assert_fails('xxx', [#{one: 1}]))
280+
catch
281+
let exp = v:exception
282+
endtry
283+
call assert_match("E731: Using a Dictionary as a String", exp)
284+
285+
let exp = ''
286+
try
287+
call assert_equal(0, assert_fails('xxx', ['E492', #{one: 1}]))
288+
catch
289+
let exp = v:exception
290+
endtry
291+
call assert_match("E731: Using a Dictionary as a String", exp)
292+
278293
try
279294
call assert_equal(1, assert_fails('xxx', 'E492', '', 'burp'))
280295
catch
@@ -289,8 +304,8 @@ func Test_assert_fail_fails()
289304
endtry
290305
call assert_match("E1174: String required for argument 5", exp)
291306

292-
call assert_equal(1, assert_fails('c0', ['', '\1']))
293-
call assert_match("Expected '\\\\\\\\1' but got 'E939: Positive count required: c0': c0", v:errors[0])
307+
call assert_equal(1, assert_fails('c0', ['', '\(.\)\1']))
308+
call assert_match("Expected '\\\\\\\\(.\\\\\\\\)\\\\\\\\1' but got 'E939: Positive count required: c0': c0", v:errors[0])
294309
call remove(v:errors, 0)
295310
endfunc
296311

src/testing.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,11 @@ f_assert_fails(typval_T *argvars, typval_T *rettv)
616616
in_assert_fails = TRUE;
617617

618618
do_cmdline_cmd(cmd);
619+
620+
// reset here for any errors reported below
621+
trylevel = save_trylevel;
622+
suppress_errthrow = FALSE;
623+
619624
if (called_emsg == called_emsg_before)
620625
{
621626
prepare_assert_error(&ga);
@@ -654,6 +659,8 @@ f_assert_fails(typval_T *argvars, typval_T *rettv)
654659
CHECK_LIST_MATERIALIZE(list);
655660
tv = &list->lv_first->li_tv;
656661
expected = tv_get_string_buf_chk(tv, buf);
662+
if (expected == NULL)
663+
goto theend;
657664
if (!pattern_match(expected, actual, FALSE))
658665
{
659666
error_found = TRUE;
@@ -667,6 +674,8 @@ f_assert_fails(typval_T *argvars, typval_T *rettv)
667674
{
668675
tv = &list->lv_u.mat.lv_last->li_tv;
669676
expected = tv_get_string_buf_chk(tv, buf);
677+
if (expected == NULL)
678+
goto theend;
670679
if (!pattern_match(expected, actual, FALSE))
671680
{
672681
error_found = TRUE;

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,8 @@ static char *(features[]) =
703703

704704
static int included_patches[] =
705705
{ /* Add new patch number below this line */
706+
/**/
707+
404,
706708
/**/
707709
403,
708710
/**/

0 commit comments

Comments
 (0)