Mirror of the Vim source from https://github.com/vim/vim
Revisão | f3f45218f923e791fa8e35e7c9040fa925c4a986 (tree) |
---|---|
Hora | 2022-05-18 04:15:03 |
Autor | Bram Moolenaar <Bram@vim....> |
Commiter | Bram Moolenaar |
patch 8.2.4975: recursive command line loop may cause a crash
Commit: https://github.com/vim/vim/commit/51f0bfb88a3554ca2dde777d78a59880d1ee37a8
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue May 17 20:11:02 2022 +0100
@@ -1581,6 +1581,7 @@ | ||
1581 | 1581 | int indent, // indent for inside conditionals |
1582 | 1582 | int clear_ccline) // clear ccline first |
1583 | 1583 | { |
1584 | + static int depth = 0; // call depth | |
1584 | 1585 | int c; |
1585 | 1586 | int i; |
1586 | 1587 | int j; |
@@ -1611,6 +1612,9 @@ | ||
1611 | 1612 | int cmdline_type; |
1612 | 1613 | int wild_type; |
1613 | 1614 | |
1615 | + // one recursion level deeper | |
1616 | + ++depth; | |
1617 | + | |
1614 | 1618 | if (ccline.cmdbuff != NULL) |
1615 | 1619 | { |
1616 | 1620 | // Being called recursively. Since ccline is global, we need to save |
@@ -1641,6 +1645,13 @@ | ||
1641 | 1645 | if (init_ccline(firstc, indent) != OK) |
1642 | 1646 | goto theend; // out of memory |
1643 | 1647 | |
1648 | + if (depth == 50) | |
1649 | + { | |
1650 | + // Somehow got into a loop recursively calling getcmdline(), bail out. | |
1651 | + emsg(_(e_command_too_recursive)); | |
1652 | + goto theend; | |
1653 | + } | |
1654 | + | |
1644 | 1655 | ExpandInit(&xpc); |
1645 | 1656 | ccline.xpc = &xpc; |
1646 | 1657 |
@@ -2576,6 +2587,7 @@ | ||
2576 | 2587 | { |
2577 | 2588 | char_u *p = ccline.cmdbuff; |
2578 | 2589 | |
2590 | + --depth; | |
2579 | 2591 | if (did_save_ccline) |
2580 | 2592 | restore_cmdline(&save_ccline); |
2581 | 2593 | else |
@@ -3392,4 +3392,16 @@ | ||
3392 | 3392 | call feedkeys(":let a\<C-R>=Check_completion()\<CR>\<Esc>", "xt") |
3393 | 3393 | endfunc |
3394 | 3394 | |
3395 | +func Test_recursive_register() | |
3396 | + let @= = '' | |
3397 | + silent! ?e/ | |
3398 | + let caught = 'no' | |
3399 | + try | |
3400 | + normal // | |
3401 | + catch /E169:/ | |
3402 | + let caught = 'yes' | |
3403 | + endtry | |
3404 | + call assert_equal('yes', caught) | |
3405 | +endfunc | |
3406 | + | |
3395 | 3407 | " vim: shiftwidth=2 sts=2 expandtab |
@@ -747,6 +747,8 @@ | ||
747 | 747 | static int included_patches[] = |
748 | 748 | { /* Add new patch number below this line */ |
749 | 749 | /**/ |
750 | + 4975, | |
751 | +/**/ | |
750 | 752 | 4974, |
751 | 753 | /**/ |
752 | 754 | 4973, |