diff src/ex_eval.c @ 25905:892f937358ea v8.2.3486

patch 8.2.3486: illegal memory access with invalid sequence of commands Commit: https://github.com/vim/vim/commit/cce81e9673fe8d056e8eef310d9919620eccb2f2 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Oct 6 22:08:11 2021 +0100 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 https://github.com/vim/vim/issues/8966) Reset did_emsg so that exception is shown as an error.
author Bram Moolenaar <Bram@vim.org>
date Wed, 06 Oct 2021 23:15:04 +0200
parents c83ebae45881
children 1c567eb92222
line wrap: on
line diff
--- 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)