comparison 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
comparison
equal deleted inserted replaced
25904:fce90a7faf9c 25905:892f937358ea
1383 1383
1384 if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0) 1384 if (cstack->cs_looplevel <= 0 || cstack->cs_idx < 0)
1385 eap->errmsg = _(err); 1385 eap->errmsg = _(err);
1386 else 1386 else
1387 { 1387 {
1388 fl = cstack->cs_flags[cstack->cs_idx]; 1388 fl = cstack->cs_flags[cstack->cs_idx];
1389 if (!(fl & csf)) 1389 if (!(fl & csf))
1390 { 1390 {
1391 // If we are in a ":while" or ":for" but used the wrong endloop 1391 // If we are in a ":while" or ":for" but used the wrong endloop
1392 // command, do not rewind to the next enclosing ":for"/":while". 1392 // command, do not rewind to the next enclosing ":for"/":while".
1393 if (fl & CSF_WHILE) 1393 if (fl & CSF_WHILE)
2005 || !(cstack->cs_flags[cstack->cs_idx] & CSF_TRUE); 2005 || !(cstack->cs_flags[cstack->cs_idx] & CSF_TRUE);
2006 2006
2007 if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY)) 2007 if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY))
2008 { 2008 {
2009 eap->errmsg = get_end_emsg(cstack); 2009 eap->errmsg = get_end_emsg(cstack);
2010
2010 // Find the matching ":try" and report what's missing. 2011 // Find the matching ":try" and report what's missing.
2011 idx = cstack->cs_idx; 2012 idx = cstack->cs_idx;
2012 do 2013 do
2013 --idx; 2014 --idx;
2014 while (idx > 0 && !(cstack->cs_flags[idx] & CSF_TRY)); 2015 while (idx > 0 && !(cstack->cs_flags[idx] & CSF_TRY));
2023 * This does not affect the script termination due to the error 2024 * This does not affect the script termination due to the error
2024 * since "trylevel" is decremented after emsg() has been called. 2025 * since "trylevel" is decremented after emsg() has been called.
2025 */ 2026 */
2026 if (did_throw) 2027 if (did_throw)
2027 discard_current_exception(); 2028 discard_current_exception();
2029
2030 // report eap->errmsg, also when there already was an error
2031 did_emsg = FALSE;
2028 } 2032 }
2029 else 2033 else
2030 { 2034 {
2031 idx = cstack->cs_idx; 2035 idx = cstack->cs_idx;
2032 2036
2103 * after errors except when this ":endtry" is not within a ":try". 2107 * after errors except when this ":endtry" is not within a ":try".
2104 * Restore "emsg_silent" if it has been reset by this try conditional. 2108 * Restore "emsg_silent" if it has been reset by this try conditional.
2105 */ 2109 */
2106 (void)cleanup_conditionals(cstack, CSF_TRY | CSF_SILENT, TRUE); 2110 (void)cleanup_conditionals(cstack, CSF_TRY | CSF_SILENT, TRUE);
2107 2111
2108 leave_block(cstack); 2112 if (cstack->cs_idx >= 0
2113 && (cstack->cs_flags[cstack->cs_idx] & CSF_TRY))
2114 leave_block(cstack);
2109 --cstack->cs_trylevel; 2115 --cstack->cs_trylevel;
2110 2116
2111 if (!skip) 2117 if (!skip)
2112 { 2118 {
2113 report_resume_pending(pending, 2119 report_resume_pending(pending,