Skip to content

Commit 48f377a

Browse files
committed
patch 8.1.0613: when executing an insecure function the secure flag is stuck
Problem: When executing an insecure function the secure flag is stuck. (Gabriel Barta) Solution: Restore "secure" instead of decrementing it. (closes #3705)
1 parent 9d302ad commit 48f377a

4 files changed

Lines changed: 34 additions & 12 deletions

File tree

src/buffer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5519,6 +5519,7 @@ chk_modeline(
55195519

55205520
if (*s != NUL) /* skip over an empty "::" */
55215521
{
5522+
int secure_save = secure;
55225523
#ifdef FEAT_EVAL
55235524
save_current_sctx = current_sctx;
55245525
current_sctx.sc_sid = SID_MODELINE;
@@ -5530,7 +5531,7 @@ chk_modeline(
55305531

55315532
retval = do_set(s, OPT_MODELINE | OPT_LOCAL | flags);
55325533

5533-
--secure;
5534+
secure = secure_save;
55345535
#ifdef FEAT_EVAL
55355536
current_sctx = save_current_sctx;
55365537
#endif

src/option.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5214,7 +5214,7 @@ do_set(
52145214

52155215
{
52165216
long_u *p = insecure_flag(opt_idx, opt_flags);
5217-
int did_inc_secure = FALSE;
5217+
int secure_saved = secure;
52185218

52195219
// When an option is set in the sandbox, from a
52205220
// modeline or in secure mode, then deal with side
@@ -5227,21 +5227,18 @@ do_set(
52275227
#endif
52285228
|| (opt_flags & OPT_MODELINE)
52295229
|| (!value_is_replaced && (*p & P_INSECURE)))
5230-
{
5231-
did_inc_secure = TRUE;
52325230
++secure;
5233-
}
52345231

5235-
// Handle side effects, and set the global value for
5236-
// ":set" on local options. Note: when setting 'syntax'
5237-
// or 'filetype' autocommands may be triggered that can
5238-
// cause havoc.
5239-
errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5232+
// Handle side effects, and set the global value
5233+
// for ":set" on local options. Note: when setting
5234+
// 'syntax' or 'filetype' autocommands may be
5235+
// triggered that can cause havoc.
5236+
errmsg = did_set_string_option(
5237+
opt_idx, (char_u **)varp,
52405238
new_value_alloced, oldval, errbuf,
52415239
opt_flags, &value_checked);
52425240

5243-
if (did_inc_secure)
5244-
--secure;
5241+
secure = secure_saved;
52455242
}
52465243

52475244
#if defined(FEAT_EVAL)

src/testdir/test_autocmd.vim

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,28 @@ func Test_OptionSet_diffmode_close()
650650
"delfunc! AutoCommandOptionSet
651651
endfunc
652652

653+
func Test_OptionSet_modeline()
654+
call test_override('starting', 1)
655+
au! OptionSet
656+
augroup set_tabstop
657+
au OptionSet tabstop call timer_start(1, {-> execute("echo 'Handler called'", "")})
658+
augroup END
659+
call writefile(['vim: set ts=7 sw=5 :', 'something'], 'XoptionsetModeline')
660+
set modeline
661+
let v:errmsg = ''
662+
call assert_fails('split XoptionsetModeline', 'E12:')
663+
call assert_equal(7, &ts)
664+
call assert_equal('', v:errmsg)
665+
666+
augroup set_tabstop
667+
au!
668+
augroup END
669+
bwipe!
670+
set ts&
671+
call delete('XoptionsetModeline')
672+
call test_override('starting', 0)
673+
endfunc
674+
653675
" Test for Bufleave autocommand that deletes the buffer we are about to edit.
654676
func Test_BufleaveWithDelete()
655677
new | edit Xfile1

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,8 @@ static char *(features[]) =
799799

800800
static int included_patches[] =
801801
{ /* Add new patch number below this line */
802+
/**/
803+
613,
802804
/**/
803805
612,
804806
/**/

0 commit comments

Comments
 (0)