0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.1.1345: stuck in sandbox with ":s/../\=Function/gn"

Problem:    Stuck in sandbox with ":s/../\=Function/gn".
Solution:   Don't skip over code to restore sandbox. (Christian Brabandt)
This commit is contained in:
Bram Moolenaar 2019-05-18 13:41:22 +02:00
parent 0d3cb73012
commit 6349e9411f
3 changed files with 19 additions and 9 deletions

View File

@ -5555,28 +5555,25 @@ do_sub(exarg_T *eap)
#ifdef FEAT_EVAL #ifdef FEAT_EVAL
if (subflags.do_count) if (subflags.do_count)
{ {
/* prevent accidentally changing the buffer by a function */ // prevent accidentally changing the buffer by a function
save_ma = curbuf->b_p_ma;
curbuf->b_p_ma = FALSE; curbuf->b_p_ma = FALSE;
sandbox++; sandbox++;
} }
/* Save flags for recursion. They can change for e.g. // Save flags for recursion. They can change for e.g.
* :s/^/\=execute("s#^##gn") */ // :s/^/\=execute("s#^##gn")
subflags_save = subflags; subflags_save = subflags;
save_ma = curbuf->b_p_ma;
#endif #endif
/* get length of substitution part */ // get length of substitution part
sublen = vim_regsub_multi(&regmatch, sublen = vim_regsub_multi(&regmatch,
sub_firstlnum - regmatch.startpos[0].lnum, sub_firstlnum - regmatch.startpos[0].lnum,
sub, sub_firstline, FALSE, p_magic, TRUE); sub, sub_firstline, FALSE, p_magic, TRUE);
#ifdef FEAT_EVAL #ifdef FEAT_EVAL
// If getting the substitute string caused an error, don't do // If getting the substitute string caused an error, don't do
// the replacement. // the replacement.
if (aborting())
goto skip;
// Don't keep flags set by a recursive call. // Don't keep flags set by a recursive call.
subflags = subflags_save; subflags = subflags_save;
if (subflags.do_count) if (aborting() || subflags.do_count)
{ {
curbuf->b_p_ma = save_ma; curbuf->b_p_ma = save_ma;
if (sandbox > 0) if (sandbox > 0)

View File

@ -638,6 +638,17 @@ func Test_nocatch_sub_failure_handling()
call assert_equal(1, error_caught) call assert_equal(1, error_caught)
call assert_equal(['1 aaa', '2 aaa', '3 aaa'], getline(1, 3)) call assert_equal(['1 aaa', '2 aaa', '3 aaa'], getline(1, 3))
" Same, but using "n" flag so that "sandbox" gets set
call setline(1, ['1 aaa', '2 aaa', '3 aaa'])
let error_caught = 0
try
%s/aaa/\=Foo()/gn
catch
let error_caught = 1
endtry
call assert_equal(1, error_caught)
call assert_equal(['1 aaa', '2 aaa', '3 aaa'], getline(1, 3))
bwipe! bwipe!
endfunc endfunc

View File

@ -767,6 +767,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1345,
/**/ /**/
1344, 1344,
/**/ /**/