0
0
mirror of https://github.com/vim/vim.git synced 2025-09-28 04:24:06 -04:00

patch 8.2.3486: illegal memory access with invalid sequence of commands

Problem:    Illegal memory access with invalid sequence of commands.
Solution:   Do not call leave_block() when not in a try block. (closes #8966)
            Reset did_emsg so that exception is shown as an error.
This commit is contained in:
Bram Moolenaar
2021-10-06 22:08:11 +01:00
parent edd7a476fb
commit cce81e9673
3 changed files with 30 additions and 2 deletions

View File

@@ -2007,6 +2007,7 @@ ex_endtry(exarg_T *eap)
if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY))
{
eap->errmsg = get_end_emsg(cstack);
// Find the matching ":try" and report what's missing.
idx = cstack->cs_idx;
do
@@ -2025,6 +2026,9 @@ ex_endtry(exarg_T *eap)
*/
if (did_throw)
discard_current_exception();
// report eap->errmsg, also when there already was an error
did_emsg = FALSE;
}
else
{
@@ -2105,6 +2109,8 @@ ex_endtry(exarg_T *eap)
*/
(void)cleanup_conditionals(cstack, CSF_TRY | CSF_SILENT, TRUE);
if (cstack->cs_idx >= 0
&& (cstack->cs_flags[cstack->cs_idx] & CSF_TRY))
leave_block(cstack);
--cstack->cs_trylevel;

View File

@@ -2295,5 +2295,25 @@ func Test_error_in_catch_and_finally()
call delete('XtestCatchAndFinally')
endfunc
" This was causing an illegal memory access
func Test_leave_block_in_endtry_not_called()
let lines =<< trim END
vim9script
try #
for x in []
if
endwhile
if
endtry
END
call writefile(lines, 'XtestEndtry')
try
source XtestEndtry
catch /E171:/
endtry
call delete('XtestEndtry')
endfunc
" Modeline {{{1
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

View File

@@ -757,6 +757,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
3486,
/**/
3485,
/**/