Patch 8.2.4975

6 views
Skip to first unread message

Bram Moolenaar

unread,
May 17, 2022, 3:16:07 PM5/17/22
to vim...@googlegroups.com

Patch 8.2.4975
Problem: Recursive command line loop may cause a crash.
Solution: Limit recursion of getcmdline().
Files: src/ex_getln.c, src/testdir/test_cmdline.vim


*** ../vim-8.2.4974/src/ex_getln.c 2022-05-09 20:09:19.286641426 +0100
--- src/ex_getln.c 2022-05-17 20:09:39.776412509 +0100
***************
*** 1581,1586 ****
--- 1581,1587 ----
int indent, // indent for inside conditionals
int clear_ccline) // clear ccline first
{
+ static int depth = 0; // call depth
int c;
int i;
int j;
***************
*** 1611,1616 ****
--- 1612,1620 ----
int cmdline_type;
int wild_type;

+ // one recursion level deeper
+ ++depth;
+
if (ccline.cmdbuff != NULL)
{
// Being called recursively. Since ccline is global, we need to save
***************
*** 1641,1646 ****
--- 1645,1657 ----
if (init_ccline(firstc, indent) != OK)
goto theend; // out of memory

+ if (depth == 50)
+ {
+ // Somehow got into a loop recursively calling getcmdline(), bail out.
+ emsg(_(e_command_too_recursive));
+ goto theend;
+ }
+
ExpandInit(&xpc);
ccline.xpc = &xpc;

***************
*** 2576,2581 ****
--- 2587,2593 ----
{
char_u *p = ccline.cmdbuff;

+ --depth;
if (did_save_ccline)
restore_cmdline(&save_ccline);
else
*** ../vim-8.2.4974/src/testdir/test_cmdline.vim 2022-05-07 12:48:24.074194794 +0100
--- src/testdir/test_cmdline.vim 2022-05-17 20:08:50.816443748 +0100
***************
*** 3392,3395 ****
--- 3392,3407 ----
call feedkeys(":let a\<C-R>=Check_completion()\<CR>\<Esc>", "xt")
endfunc

+ func Test_recursive_register()
+ let @= = ''
+ silent! ? e /
+ let caught = 'no'
+ try
+ normal / /
+ catch /E169:/
+ let caught = 'yes'
+ endtry
+ call assert_equal('yes', caught)
+ endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.4974/src/version.c 2022-05-17 17:47:02.084506580 +0100
--- src/version.c 2022-05-17 19:51:54.325092314 +0100
***************
*** 748,749 ****
--- 748,751 ----
{ /* Add new patch number below this line */
+ /**/
+ 4975,
/**/

--
hundred-and-one symptoms of being an internet addict:
224. You set up your own Web page. You set up a Web page for each
of your kids... and your pets.

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