Patch 8.2.0098

8 views
Skip to first unread message

Bram Moolenaar

unread,
Jan 7, 2020, 3:00:13 PM1/7/20
to vim...@googlegroups.com

Patch 8.2.0098
Problem: Exe stack length can be wrong without being detected.
Solution: Add a check when ABORT_ON_INTERNAL_ERROR is defined.
Files: src/macros.h, src/autocmd.c, src/buffer.c, src/ex_docmd.c,
src/main.c, src/map.c, src/scriptfile.c, src/spellfile.c,
src/userfunc.c


*** ../vim-8.2.0097/src/macros.h 2019-11-30 22:40:44.000000000 +0100
--- src/macros.h 2020-01-07 20:40:36.529317529 +0100
***************
*** 344,346 ****
--- 344,358 ----
#else
# define ERROR_IF_POPUP_WINDOW 0
#endif
+
+
+ #ifdef ABORT_ON_INTERNAL_ERROR
+ # define ESTACK_CHECK_DECLARATION int estack_len_before;
+ # define ESTACK_CHECK_SETUP estack_len_before = exestack.ga_len;
+ # define ESTACK_CHECK_NOW if (estack_len_before != exestack.ga_len) \
+ siemsg("Exestack length expected: %d, actual: %d", estack_len_before, exestack.ga_len);
+ #else
+ # define ESTACK_CHECK_DECLARATION
+ # define ESTACK_CHECK_SETUP
+ # define ESTACK_CHECK_NOW
+ #endif
*** ../vim-8.2.0097/src/autocmd.c 2019-12-29 23:04:20.286639911 +0100
--- src/autocmd.c 2020-01-07 20:27:29.308509646 +0100
***************
*** 1827,1832 ****
--- 1827,1833 ----
int did_save_redobuff = FALSE;
save_redo_T save_redo;
int save_KeyTyped = KeyTyped;
+ ESTACK_CHECK_DECLARATION

/*
* Quickly return if there are no autocommands for this event or
***************
*** 2021,2026 ****
--- 2022,2028 ----

// name and lnum are filled in later
estack_push(ETYPE_AUCMD, NULL, 0);
+ ESTACK_CHECK_SETUP

#ifdef FEAT_EVAL
save_current_sctx = current_sctx;
***************
*** 2124,2129 ****
--- 2126,2132 ----
filechangeshell_busy = FALSE;
autocmd_nested = save_autocmd_nested;
vim_free(SOURCING_NAME);
+ ESTACK_CHECK_NOW
estack_pop();
vim_free(autocmd_fname);
autocmd_fname = save_autocmd_fname;
*** ../vim-8.2.0097/src/buffer.c 2020-01-03 20:59:55.847158293 +0100
--- src/buffer.c 2020-01-07 20:36:13.558342863 +0100
***************
*** 5287,5292 ****
--- 5287,5293 ----
#ifdef FEAT_EVAL
sctx_T save_current_sctx;
#endif
+ ESTACK_CHECK_DECLARATION

prev = -1;
for (s = ml_get(lnum); *s != NUL; ++s)
***************
*** 5330,5335 ****
--- 5331,5337 ----

// prepare for emsg()
estack_push(ETYPE_MODELINE, (char_u *)"modelines", lnum);
+ ESTACK_CHECK_SETUP

end = FALSE;
while (end == FALSE)
***************
*** 5390,5395 ****
--- 5392,5398 ----
s = e + 1; // advance to next part
}

+ ESTACK_CHECK_NOW
estack_pop();
vim_free(linecopy);
}
*** ../vim-8.2.0097/src/ex_docmd.c 2020-01-06 21:47:17.040023214 +0100
--- src/ex_docmd.c 2020-01-07 20:36:23.574303312 +0100
***************
*** 645,650 ****
--- 645,651 ----
# define cmd_cookie cookie
#endif
static int call_depth = 0; // recursiveness
+ ESTACK_CHECK_DECLARATION

#ifdef FEAT_EVAL
// For every pair of do_cmdline()/do_one_cmd() calls, use an extra memory
***************
*** 1260,1265 ****
--- 1261,1267 ----

estack_push(ETYPE_EXCEPT, current_exception->throw_name,
current_exception->throw_lnum);
+ ESTACK_CHECK_SETUP
current_exception->throw_name = NULL;

discard_current_exception(); // uses IObuff if 'verbose'
***************
*** 1284,1289 ****
--- 1286,1292 ----
vim_free(p);
}
vim_free(SOURCING_NAME);
+ ESTACK_CHECK_NOW
estack_pop();
}

*** ../vim-8.2.0097/src/main.c 2019-12-29 23:04:20.290639897 +0100
--- src/main.c 2020-01-07 20:55:05.826031934 +0100
***************
*** 3086,3101 ****
--- 3086,3104 ----
char_u **cmds = parmp->pre_commands;
int cnt = parmp->n_pre_commands;
int i;
+ ESTACK_CHECK_DECLARATION

if (cnt > 0)
{
curwin->w_cursor.lnum = 0; // just in case..
estack_push(ETYPE_ARGS, (char_u *)_("pre-vimrc command line"), 0);
+ ESTACK_CHECK_SETUP
# ifdef FEAT_EVAL
current_sctx.sc_sid = SID_CMDARG;
# endif
for (i = 0; i < cnt; ++i)
do_cmdline_cmd(cmds[i]);
+ ESTACK_CHECK_NOW
estack_pop();
# ifdef FEAT_EVAL
current_sctx.sc_sid = 0;
***************
*** 3111,3116 ****
--- 3114,3120 ----
exe_commands(mparm_T *parmp)
{
int i;
+ ESTACK_CHECK_DECLARATION

/*
* We start commands on line 0, make "vim +/pat file" match a
***************
*** 3121,3126 ****
--- 3125,3131 ----
if (parmp->tagname == NULL && curwin->w_cursor.lnum <= 1)
curwin->w_cursor.lnum = 0;
estack_push(ETYPE_ARGS, (char_u *)"command line", 0);
+ ESTACK_CHECK_SETUP
#ifdef FEAT_EVAL
current_sctx.sc_sid = SID_CARG;
current_sctx.sc_seq = 0;
***************
*** 3131,3136 ****
--- 3136,3142 ----
if (parmp->cmds_tofree[i])
vim_free(parmp->commands[i]);
}
+ ESTACK_CHECK_NOW
estack_pop();
#ifdef FEAT_EVAL
current_sctx.sc_sid = 0;
***************
*** 3340,3351 ****
--- 3346,3359 ----
#ifdef FEAT_EVAL
sctx_T save_current_sctx;
#endif
+ ESTACK_CHECK_DECLARATION

if ((initstr = mch_getenv(env)) != NULL && *initstr != NUL)
{
if (is_viminit)
vimrc_found(NULL, NULL);
estack_push(ETYPE_ENV, env, 0);
+ ESTACK_CHECK_SETUP
#ifdef FEAT_EVAL
save_current_sctx = current_sctx;
current_sctx.sc_sid = SID_ENV;
***************
*** 3355,3360 ****
--- 3363,3369 ----
#endif
do_cmdline_cmd(initstr);

+ ESTACK_CHECK_NOW
estack_pop();
#ifdef FEAT_EVAL
current_sctx = save_current_sctx;
*** ../vim-8.2.0097/src/map.c 2019-12-29 23:04:20.290639897 +0100
--- src/map.c 2020-01-07 20:36:55.214178671 +0100
***************
*** 1918,1927 ****
--- 1918,1929 ----
int abbr;
int hash;
buf_T *bp;
+ ESTACK_CHECK_DECLARATION

validate_maphash();
// avoids giving error messages
estack_push(ETYPE_INTERNAL, (char_u *)"mappings", 0);
+ ESTACK_CHECK_SETUP

// Do this once for each buffer, and then once for global
// mappings/abbreviations with bp == NULL
***************
*** 1978,1983 ****
--- 1980,1986 ----
if (bp == NULL)
break;
}
+ ESTACK_CHECK_NOW
estack_pop();
}

*** ../vim-8.2.0097/src/scriptfile.c 2020-01-06 19:53:38.882236516 +0100
--- src/scriptfile.c 2020-01-07 20:36:59.874160361 +0100
***************
*** 1099,1104 ****
--- 1099,1105 ----
proftime_T wait_start;
#endif
int trigger_source_post = FALSE;
+ ESTACK_CHECK_DECLARATION

p = expand_env_save(fname);
if (p == NULL)
***************
*** 1216,1221 ****
--- 1217,1223 ----

// Keep the sourcing name/lnum, for recursive calls.
estack_push(ETYPE_SCRIPT, fname_exp, 0);
+ ESTACK_CHECK_SETUP

#ifdef STARTUPTIME
if (time_fd != NULL)
***************
*** 1355,1360 ****
--- 1357,1363 ----

if (got_int)
emsg(_(e_interr));
+ ESTACK_CHECK_NOW
estack_pop();
if (p_verbose > 1)
{
*** ../vim-8.2.0097/src/spellfile.c 2020-01-07 20:11:38.152168717 +0100
--- src/spellfile.c 2020-01-07 20:42:18.832924611 +0100
***************
*** 353,358 ****
--- 353,359 ----
int c = 0;
int res;
int did_estack_push = FALSE;
+ ESTACK_CHECK_DECLARATION

fd = mch_fopen((char *)fname, "r");
if (fd == NULL)
***************
*** 393,398 ****
--- 394,400 ----

// Set sourcing_name, so that error messages mention the file name.
estack_push(ETYPE_SPELL, fname, 0);
+ ESTACK_CHECK_SETUP
did_estack_push = TRUE;

/*
***************
*** 581,587 ****
--- 583,592 ----
if (fd != NULL)
fclose(fd);
if (did_estack_push)
+ {
+ ESTACK_CHECK_NOW
estack_pop();
+ }

return lp;
}
*** ../vim-8.2.0097/src/userfunc.c 2020-01-02 14:31:17.944876303 +0100
--- src/userfunc.c 2020-01-07 20:37:37.106014337 +0100
***************
*** 793,798 ****
--- 793,799 ----
proftime_T call_start;
int started_profiling = FALSE;
#endif
+ ESTACK_CHECK_DECLARATION

// If depth of calling is getting too high, don't execute the function
if (depth >= p_mfd)
***************
*** 969,974 ****
--- 970,976 ----
}

estack_push_ufunc(ETYPE_UFUNC, fp, 1);
+ ESTACK_CHECK_SETUP
if (p_verbose >= 12)
{
++no_wait_return;
***************
*** 1115,1120 ****
--- 1117,1123 ----
--no_wait_return;
}

+ ESTACK_CHECK_NOW
estack_pop();
current_sctx = save_current_sctx;
#ifdef FEAT_PROFILE
*** ../vim-8.2.0097/src/version.c 2020-01-07 20:11:38.152168717 +0100
--- src/version.c 2020-01-07 20:49:36.487266082 +0100
***************
*** 744,745 ****
--- 744,747 ----
{ /* Add new patch number below this line */
+ /**/
+ 98,
/**/

--
It is illegal for anyone to give lighted cigars to dogs, cats, and other
domesticated animal kept as pets.
[real standing law in Illinois, United States of America]

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages