Commit ded9c614 authored by Jan Edmund Lazo's avatar Jan Edmund Lazo Committed by James McCoy

vim-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 vim/vim#3705)
https://github.com/vim/vim/commit/48f377a476e4a3312aa0e3535aba170484b59483

(cherry picked from commit 9dca0b27)
Signed-off-by: James McCoy's avatarJames McCoy <jamessan@debian.org>
parent 04b9ef8b
......@@ -4923,6 +4923,7 @@ chk_modeline (
*e = NUL; /* truncate the set command */
if (*s != NUL) { /* skip over an empty "::" */
const int secure_save = secure;
save_SID = current_SID;
current_SID = SID_MODELINE;
// Make sure no risky things are executed as a side effect.
......@@ -4930,7 +4931,7 @@ chk_modeline (
retval = do_set(s, OPT_MODELINE | OPT_LOCAL | flags);
--secure;
secure = secure_save;
current_SID = save_SID;
if (retval == FAIL) /* stop if error found */
break;
......
......@@ -1779,8 +1779,8 @@ do_set (
saved_newval = (newval != NULL) ? xstrdup((char *)newval) : 0;
{
unsigned int *p = insecure_flag(opt_idx, opt_flags);
int did_inc_secure = FALSE;
uint32_t *p = insecure_flag(opt_idx, opt_flags);
const int secure_saved = secure;
// When an option is set in the sandbox, from a
// modeline or in secure mode, then deal with side
......@@ -1788,29 +1788,23 @@ do_set (
// set with the P_INSECURE flag and is not
// completely replaced.
if (secure
#ifdef HAVE_SANDBOX
|| sandbox != 0
#endif
|| (opt_flags & OPT_MODELINE)
|| (!value_is_replaced && (*p & P_INSECURE)))
{
did_inc_secure = TRUE;
++secure;
|| sandbox != 0
|| (opt_flags & OPT_MODELINE)
|| (!value_is_replaced && (*p & P_INSECURE))) {
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.
// 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, sizeof(errbuf),
opt_flags, &value_checked);
if (did_inc_secure) {
--secure;
}
}
secure = secure_saved;
}
if (errmsg == NULL) {
if (!starting) {
......
......@@ -652,6 +652,29 @@ func Test_OptionSet_diffmode_close()
"delfunc! AutoCommandOptionSet
endfunc
func Test_OptionSet_modeline()
throw 'skipped: Nvim does not support test_override()'
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment