mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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)
93343725b5
This commit is contained in:
parent
3e78319ac6
commit
b5582d1b32
@ -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;
|
||||
|
@ -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',
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user