mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 9.0.1511: crash when using wrong arg types to assert_match()
Problem: Crash when using wrong arg types to assert_match(). Solution: Check for NULL pointer. (closes #12349)
This commit is contained in:
parent
70e8028a4d
commit
12e7a1fe75
@ -335,6 +335,23 @@ func Test_assert_fail_fails()
|
|||||||
call remove(v:errors, 0)
|
call remove(v:errors, 0)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_assert_wrong_arg_emsg_off()
|
||||||
|
CheckFeature folding
|
||||||
|
|
||||||
|
new
|
||||||
|
call setline(1, ['foo', 'bar'])
|
||||||
|
1,2fold
|
||||||
|
|
||||||
|
" This used to crash Vim
|
||||||
|
let &l:foldtext = 'assert_match({}, {})'
|
||||||
|
redraw!
|
||||||
|
|
||||||
|
let &l:foldtext = 'assert_equalfile({}, {})'
|
||||||
|
redraw!
|
||||||
|
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_assert_fails_in_try_block()
|
func Test_assert_fails_in_try_block()
|
||||||
try
|
try
|
||||||
call assert_equal(0, assert_fails('throw "error"'))
|
call assert_equal(0, assert_fails('throw "error"'))
|
||||||
|
@ -281,9 +281,6 @@ assert_match_common(typval_T *argvars, assert_type_T atype)
|
|||||||
garray_T ga;
|
garray_T ga;
|
||||||
char_u buf1[NUMBUFLEN];
|
char_u buf1[NUMBUFLEN];
|
||||||
char_u buf2[NUMBUFLEN];
|
char_u buf2[NUMBUFLEN];
|
||||||
int called_emsg_before = called_emsg;
|
|
||||||
char_u *pat;
|
|
||||||
char_u *text;
|
|
||||||
|
|
||||||
if (in_vim9script()
|
if (in_vim9script()
|
||||||
&& (check_for_string_arg(argvars, 0) == FAIL
|
&& (check_for_string_arg(argvars, 0) == FAIL
|
||||||
@ -291,9 +288,9 @@ assert_match_common(typval_T *argvars, assert_type_T atype)
|
|||||||
|| check_for_opt_string_arg(argvars, 2) == FAIL))
|
|| check_for_opt_string_arg(argvars, 2) == FAIL))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
pat = tv_get_string_buf_chk(&argvars[0], buf1);
|
char_u *pat = tv_get_string_buf_chk(&argvars[0], buf1);
|
||||||
text = tv_get_string_buf_chk(&argvars[1], buf2);
|
char_u *text = tv_get_string_buf_chk(&argvars[1], buf2);
|
||||||
if (called_emsg == called_emsg_before
|
if (pat != NULL && text != NULL
|
||||||
&& pattern_match(pat, text, FALSE) != (atype == ASSERT_MATCH))
|
&& pattern_match(pat, text, FALSE) != (atype == ASSERT_MATCH))
|
||||||
{
|
{
|
||||||
prepare_assert_error(&ga);
|
prepare_assert_error(&ga);
|
||||||
@ -420,24 +417,23 @@ assert_equalfile(typval_T *argvars)
|
|||||||
{
|
{
|
||||||
char_u buf1[NUMBUFLEN];
|
char_u buf1[NUMBUFLEN];
|
||||||
char_u buf2[NUMBUFLEN];
|
char_u buf2[NUMBUFLEN];
|
||||||
int called_emsg_before = called_emsg;
|
|
||||||
char_u *fname1 = tv_get_string_buf_chk(&argvars[0], buf1);
|
char_u *fname1 = tv_get_string_buf_chk(&argvars[0], buf1);
|
||||||
char_u *fname2 = tv_get_string_buf_chk(&argvars[1], buf2);
|
char_u *fname2 = tv_get_string_buf_chk(&argvars[1], buf2);
|
||||||
garray_T ga;
|
|
||||||
FILE *fd1;
|
FILE *fd1;
|
||||||
FILE *fd2;
|
FILE *fd2;
|
||||||
char line1[200];
|
char line1[200];
|
||||||
char line2[200];
|
char line2[200];
|
||||||
int lineidx = 0;
|
int lineidx = 0;
|
||||||
|
|
||||||
if (called_emsg > called_emsg_before)
|
if (fname1 == NULL || fname2 == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
IObuff[0] = NUL;
|
IObuff[0] = NUL;
|
||||||
fd1 = mch_fopen((char *)fname1, READBIN);
|
fd1 = mch_fopen((char *)fname1, READBIN);
|
||||||
if (fd1 == NULL)
|
if (fd1 == NULL)
|
||||||
{
|
{
|
||||||
vim_snprintf((char *)IObuff, IOSIZE, (char *)e_cant_read_file_str, fname1);
|
vim_snprintf((char *)IObuff, IOSIZE, (char *)e_cant_read_file_str,
|
||||||
|
fname1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -445,7 +441,8 @@ assert_equalfile(typval_T *argvars)
|
|||||||
if (fd2 == NULL)
|
if (fd2 == NULL)
|
||||||
{
|
{
|
||||||
fclose(fd1);
|
fclose(fd1);
|
||||||
vim_snprintf((char *)IObuff, IOSIZE, (char *)e_cant_read_file_str, fname2);
|
vim_snprintf((char *)IObuff, IOSIZE, (char *)e_cant_read_file_str,
|
||||||
|
fname2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -498,8 +495,10 @@ assert_equalfile(typval_T *argvars)
|
|||||||
fclose(fd2);
|
fclose(fd2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IObuff[0] != NUL)
|
if (IObuff[0] != NUL)
|
||||||
{
|
{
|
||||||
|
garray_T ga;
|
||||||
prepare_assert_error(&ga);
|
prepare_assert_error(&ga);
|
||||||
if (argvars[2].v_type != VAR_UNKNOWN)
|
if (argvars[2].v_type != VAR_UNKNOWN)
|
||||||
{
|
{
|
||||||
@ -528,6 +527,7 @@ assert_equalfile(typval_T *argvars)
|
|||||||
ga_clear(&ga);
|
ga_clear(&ga);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -695,6 +695,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 */
|
||||||
|
/**/
|
||||||
|
1511,
|
||||||
/**/
|
/**/
|
||||||
1510,
|
1510,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user