diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-10-06 22:08:11 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-10-06 22:08:11 +0100 |
commit | cce81e9673fe8d056e8eef310d9919620eccb2f2 (patch) | |
tree | 2899b652b178f018a5032bd0ad6d5248462843da /src | |
parent | edd7a476fbcba199dc0b026461917912c574c629 (diff) |
patch 8.2.3486: illegal memory access with invalid sequence of commandsv8.2.3486
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/ex_eval.c | 10 | ||||
-rw-r--r-- | src/testdir/test_trycatch.vim | 20 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 30 insertions, 2 deletions
diff --git a/src/ex_eval.c b/src/ex_eval.c index ee6816a396..1142280bae 100644 --- a/src/ex_eval.c +++ b/src/ex_eval.c @@ -1385,7 +1385,7 @@ ex_endwhile(exarg_T *eap) eap->errmsg = _(err); else { - fl = cstack->cs_flags[cstack->cs_idx]; + fl = cstack->cs_flags[cstack->cs_idx]; if (!(fl & csf)) { // If we are in a ":while" or ":for" but used the wrong endloop @@ -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,7 +2109,9 @@ ex_endtry(exarg_T *eap) */ (void)cleanup_conditionals(cstack, CSF_TRY | CSF_SILENT, TRUE); - leave_block(cstack); + if (cstack->cs_idx >= 0 + && (cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) + leave_block(cstack); --cstack->cs_trylevel; if (!skip) diff --git a/src/testdir/test_trycatch.vim b/src/testdir/test_trycatch.vim index 4b8f7efbd1..50c1c65f2d 100644 --- a/src/testdir/test_trycatch.vim +++ b/src/testdir/test_trycatch.vim @@ -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 diff --git a/src/version.c b/src/version.c index 987f6ffc7d..4c66b2425e 100644 --- a/src/version.c +++ b/src/version.c @@ -758,6 +758,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3486, +/**/ 3485, /**/ 3484, |