|
14 | 14 | #include "vim.h" |
15 | 15 |
|
16 | 16 | #if defined(FEAT_EVAL) || defined(PROTO) |
17 | | -/* function flags */ |
18 | | -#define FC_ABORT 0x01 /* abort function on error */ |
19 | | -#define FC_RANGE 0x02 /* function accepts range */ |
20 | | -#define FC_DICT 0x04 /* Dict function, uses "self" */ |
21 | | -#define FC_CLOSURE 0x08 /* closure, uses outer scope variables */ |
22 | | -#define FC_DELETED 0x10 /* :delfunction used while uf_refcount > 0 */ |
23 | | -#define FC_REMOVED 0x20 /* function redefined while uf_refcount > 0 */ |
| 17 | +// flags used in uf_flags |
| 18 | +#define FC_ABORT 0x01 // abort function on error |
| 19 | +#define FC_RANGE 0x02 // function accepts range |
| 20 | +#define FC_DICT 0x04 // Dict function, uses "self" |
| 21 | +#define FC_CLOSURE 0x08 // closure, uses outer scope variables |
| 22 | +#define FC_DELETED 0x10 // :delfunction used while uf_refcount > 0 |
| 23 | +#define FC_REMOVED 0x20 // function redefined while uf_refcount > 0 |
| 24 | +#define FC_SANDBOX 0x40 // function defined in the sandbox |
24 | 25 |
|
25 | 26 | /* From user function to hashitem and back. */ |
26 | 27 | #define UF2HIKEY(fp) ((fp)->uf_name) |
@@ -296,6 +297,8 @@ get_lambda_tv(char_u **arg, typval_T *rettv, int evaluate) |
296 | 297 | if (prof_def_func()) |
297 | 298 | func_do_profile(fp); |
298 | 299 | #endif |
| 300 | + if (sandbox) |
| 301 | + flags |= FC_SANDBOX; |
299 | 302 | fp->uf_varargs = TRUE; |
300 | 303 | fp->uf_flags = flags; |
301 | 304 | fp->uf_calls = 0; |
@@ -688,6 +691,7 @@ call_user_func( |
688 | 691 | char_u *save_sourcing_name; |
689 | 692 | linenr_T save_sourcing_lnum; |
690 | 693 | scid_T save_current_SID; |
| 694 | + int using_sandbox = FALSE; |
691 | 695 | funccall_T *fc; |
692 | 696 | int save_did_emsg; |
693 | 697 | static int depth = 0; |
@@ -854,6 +858,13 @@ call_user_func( |
854 | 858 | save_sourcing_name = sourcing_name; |
855 | 859 | save_sourcing_lnum = sourcing_lnum; |
856 | 860 | sourcing_lnum = 1; |
| 861 | + |
| 862 | + if (fp->uf_flags & FC_SANDBOX) |
| 863 | + { |
| 864 | + using_sandbox = TRUE; |
| 865 | + ++sandbox; |
| 866 | + } |
| 867 | + |
857 | 868 | /* need space for function name + ("function " + 3) or "[number]" */ |
858 | 869 | len = (save_sourcing_name == NULL ? 0 : STRLEN(save_sourcing_name)) |
859 | 870 | + STRLEN(fp->uf_name) + 20; |
@@ -1020,6 +1031,8 @@ call_user_func( |
1020 | 1031 | if (do_profiling == PROF_YES) |
1021 | 1032 | script_prof_restore(&wait_start); |
1022 | 1033 | #endif |
| 1034 | + if (using_sandbox) |
| 1035 | + --sandbox; |
1023 | 1036 |
|
1024 | 1037 | if (p_verbose >= 12 && sourcing_name != NULL) |
1025 | 1038 | { |
@@ -2429,6 +2442,8 @@ ex_function(exarg_T *eap) |
2429 | 2442 | func_do_profile(fp); |
2430 | 2443 | #endif |
2431 | 2444 | fp->uf_varargs = varargs; |
| 2445 | + if (sandbox) |
| 2446 | + flags |= FC_SANDBOX; |
2432 | 2447 | fp->uf_flags = flags; |
2433 | 2448 | fp->uf_calls = 0; |
2434 | 2449 | fp->uf_script_ID = current_SID; |
|
0 commit comments