aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2019-03-23 00:58:00 -0400
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2019-03-23 01:25:33 -0400
commitb5582d1b32fe721931e3cd28daeb1bca51beb53c (patch)
treea63e9eecec9d835a0f93e3c3ee3393d051cac5ff
parent3e78319ac608abadd5204e00295dc3ace7e2edd8 (diff)
downloadrneovim-b5582d1b32fe721931e3cd28daeb1bca51beb53c.tar.gz
rneovim-b5582d1b32fe721931e3cd28daeb1bca51beb53c.tar.bz2
rneovim-b5582d1b32fe721931e3cd28daeb1bca51beb53c.zip
vim-patch:8.1.0177: defining function in sandbox is inconsistent
Problem: Defining function in sandbox is inconsistent, cannot use :function but can define a lambda. Solution: Allow defining a function in the sandbox, but also use the sandbox when executing it. (closes vim/vim#3182) https://github.com/vim/vim/commit/93343725b5fa1cf580a24302455980faacae8ee2
-rw-r--r--src/nvim/eval.c19
-rw-r--r--src/nvim/ex_cmds.lua2
2 files changed, 19 insertions, 2 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index df677a3a13..0961e5fd92 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -241,13 +241,14 @@ typedef enum {
///< the value (prevents error message).
} GetLvalFlags;
-// function flags
+// flags used in uf_flags
#define FC_ABORT 0x01 // abort function on error
#define FC_RANGE 0x02 // function accepts range
#define FC_DICT 0x04 // Dict function, uses "self"
#define FC_CLOSURE 0x08 // closure, uses outer scope variables
#define FC_DELETED 0x10 // :delfunction used while uf_refcount > 0
#define FC_REMOVED 0x20 // function redefined while uf_refcount > 0
+#define FC_SANDBOX 0x40 // function defined in the sandbox
// The names of packages that once were loaded are remembered.
static garray_T ga_loaded = { 0, 0, sizeof(char_u *), 4, NULL };
@@ -5853,6 +5854,9 @@ static int get_lambda_tv(char_u **arg, typval_T *rettv, bool evaluate)
if (prof_def_func()) {
func_do_profile(fp);
}
+ if (sandbox) {
+ flags |= FC_SANDBOX;
+ }
fp->uf_varargs = true;
fp->uf_flags = flags;
fp->uf_calls = 0;
@@ -20352,6 +20356,9 @@ void ex_function(exarg_T *eap)
if (prof_def_func())
func_do_profile(fp);
fp->uf_varargs = varargs;
+ if (sandbox) {
+ flags |= FC_SANDBOX;
+ }
fp->uf_flags = flags;
fp->uf_calls = 0;
fp->uf_script_ID = current_SID;
@@ -21342,6 +21349,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars,
char_u *save_sourcing_name;
linenr_T save_sourcing_lnum;
scid_T save_current_SID;
+ bool using_sandbox = false;
funccall_T *fc;
int save_did_emsg;
static int depth = 0;
@@ -21499,6 +21507,12 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars,
save_sourcing_name = sourcing_name;
save_sourcing_lnum = sourcing_lnum;
sourcing_lnum = 1;
+
+ if (fp->uf_flags & FC_SANDBOX) {
+ using_sandbox = true;
+ sandbox++;
+ }
+
// need space for new sourcing_name:
// * save_sourcing_name
// * "["number"].." or "function "
@@ -21659,6 +21673,9 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars,
if (do_profiling_yes) {
script_prof_restore(&wait_start);
}
+ if (using_sandbox) {
+ sandbox--;
+ }
if (p_verbose >= 12 && sourcing_name != NULL) {
++no_wait_return;
diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua
index 4806eff1b4..0f69d476f9 100644
--- a/src/nvim/ex_cmds.lua
+++ b/src/nvim/ex_cmds.lua
@@ -1004,7 +1004,7 @@ return {
},
{
command='function',
- flags=bit.bor(EXTRA, BANG, CMDWIN),
+ flags=bit.bor(EXTRA, BANG, SBOXOK, CMDWIN),
addr_type=ADDR_LINES,
func='ex_function',
},