]> granicus.if.org Git - vim/commitdiff
patch 8.1.0613: when executing an insecure function the secure flag is stuck v8.1.0613
authorBram Moolenaar <Bram@vim.org>
Fri, 21 Dec 2018 12:03:28 +0000 (13:03 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 21 Dec 2018 12:03:28 +0000 (13:03 +0100)
Problem:    When executing an insecure function the secure flag is stuck.
            (Gabriel Barta)
Solution:   Restore "secure" instead of decrementing it. (closes #3705)

src/buffer.c
src/option.c
src/testdir/test_autocmd.vim
src/version.c

index bb940691c3d1ef59817fb2e3809939e020fc23f6..66068d9637854c3b4043dd28b844a208b72e3e15 100644 (file)
@@ -5519,6 +5519,7 @@ chk_modeline(
 
            if (*s != NUL)              /* skip over an empty "::" */
            {
+               int secure_save = secure;
 #ifdef FEAT_EVAL
                save_current_sctx = current_sctx;
                current_sctx.sc_sid = SID_MODELINE;
@@ -5530,7 +5531,7 @@ chk_modeline(
 
                retval = do_set(s, OPT_MODELINE | OPT_LOCAL | flags);
 
-               --secure;
+               secure = secure_save;
 #ifdef FEAT_EVAL
                current_sctx = save_current_sctx;
 #endif
index f8e91e45cdfb8cb7cf54d39c18a684acaabb6c5d..3ab355f6cd124a4f59bbe3241aea06665747dbd8 100644 (file)
@@ -5214,7 +5214,7 @@ do_set(
 
                        {
                            long_u *p = insecure_flag(opt_idx, opt_flags);
-                           int     did_inc_secure = FALSE;
+                           int     secure_saved = secure;
 
                            // When an option is set in the sandbox, from a
                            // modeline or in secure mode, then deal with side
@@ -5227,21 +5227,18 @@ do_set(
 #endif
                                    || (opt_flags & OPT_MODELINE)
                                    || (!value_is_replaced && (*p & P_INSECURE)))
-                           {
-                               did_inc_secure = TRUE;
                                ++secure;
-                           }
 
-                           // Handle side effects, and set the global value for
-                           // ":set" on local options. Note: when setting 'syntax'
-                           // or 'filetype' autocommands may be triggered that can
-                           // cause havoc.
-                           errmsg = did_set_string_option(opt_idx, (char_u **)varp,
+                           // Handle side effects, and set the global value
+                           // for ":set" on local options. Note: when setting
+                           // 'syntax' or 'filetype' autocommands may be
+                           // triggered that can cause havoc.
+                           errmsg = did_set_string_option(
+                                   opt_idx, (char_u **)varp,
                                    new_value_alloced, oldval, errbuf,
                                    opt_flags, &value_checked);
 
-                           if (did_inc_secure)
-                               --secure;
+                           secure = secure_saved;
                        }
 
 #if defined(FEAT_EVAL)
index b05b210c20b7c79f874f3d3d8c9b034761f22b90..b839bbb474f877e51c17d98c2ac82141ce32b9b7 100644 (file)
@@ -650,6 +650,28 @@ func Test_OptionSet_diffmode_close()
   "delfunc! AutoCommandOptionSet
 endfunc
 
+func Test_OptionSet_modeline()
+  call test_override('starting', 1)
+  au! OptionSet
+  augroup set_tabstop
+    au OptionSet tabstop call timer_start(1, {-> execute("echo 'Handler called'", "")})
+  augroup END
+  call writefile(['vim: set ts=7 sw=5 :', 'something'], 'XoptionsetModeline')
+  set modeline
+  let v:errmsg = ''
+  call assert_fails('split XoptionsetModeline', 'E12:')
+  call assert_equal(7, &ts)
+  call assert_equal('', v:errmsg)
+
+  augroup set_tabstop
+    au!
+  augroup END
+  bwipe!
+  set ts&
+  call delete('XoptionsetModeline')
+  call test_override('starting', 0)
+endfunc
+
 " Test for Bufleave autocommand that deletes the buffer we are about to edit.
 func Test_BufleaveWithDelete()
   new | edit Xfile1
index a605def475fdaaf3e728d38544afa18b1a9a76af..c6d55d855508b4307dbecf89d6faaa3224111e50 100644 (file)
@@ -799,6 +799,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    613,
 /**/
     612,
 /**/