Mercurial > vim
comparison src/userfunc.c @ 14323:9df95cf9ea7e v8.1.0177
patch 8.1.0177: defining function in sandbox is inconsistent
commit https://github.com/vim/vim/commit/93343725b5fa1cf580a24302455980faacae8ee2
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jul 10 19:39:18 2018 +0200
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 #3182)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 10 Jul 2018 19:45:05 +0200 |
parents | f761a55a8aed |
children | 2fba714294b9 |
comparison
equal
deleted
inserted
replaced
14322:b2316311ea81 | 14323:9df95cf9ea7e |
---|---|
12 */ | 12 */ |
13 | 13 |
14 #include "vim.h" | 14 #include "vim.h" |
15 | 15 |
16 #if defined(FEAT_EVAL) || defined(PROTO) | 16 #if defined(FEAT_EVAL) || defined(PROTO) |
17 /* function flags */ | 17 // flags used in uf_flags |
18 #define FC_ABORT 0x01 /* abort function on error */ | 18 #define FC_ABORT 0x01 // abort function on error |
19 #define FC_RANGE 0x02 /* function accepts range */ | 19 #define FC_RANGE 0x02 // function accepts range |
20 #define FC_DICT 0x04 /* Dict function, uses "self" */ | 20 #define FC_DICT 0x04 // Dict function, uses "self" |
21 #define FC_CLOSURE 0x08 /* closure, uses outer scope variables */ | 21 #define FC_CLOSURE 0x08 // closure, uses outer scope variables |
22 #define FC_DELETED 0x10 /* :delfunction used while uf_refcount > 0 */ | 22 #define FC_DELETED 0x10 // :delfunction used while uf_refcount > 0 |
23 #define FC_REMOVED 0x20 /* function redefined 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 /* From user function to hashitem and back. */ | 26 /* From user function to hashitem and back. */ |
26 #define UF2HIKEY(fp) ((fp)->uf_name) | 27 #define UF2HIKEY(fp) ((fp)->uf_name) |
27 #define HIKEY2UF(p) ((ufunc_T *)(p - offsetof(ufunc_T, uf_name))) | 28 #define HIKEY2UF(p) ((ufunc_T *)(p - offsetof(ufunc_T, uf_name))) |
28 #define HI2UF(hi) HIKEY2UF((hi)->hi_key) | 29 #define HI2UF(hi) HIKEY2UF((hi)->hi_key) |
294 | 295 |
295 #ifdef FEAT_PROFILE | 296 #ifdef FEAT_PROFILE |
296 if (prof_def_func()) | 297 if (prof_def_func()) |
297 func_do_profile(fp); | 298 func_do_profile(fp); |
298 #endif | 299 #endif |
300 if (sandbox) | |
301 flags |= FC_SANDBOX; | |
299 fp->uf_varargs = TRUE; | 302 fp->uf_varargs = TRUE; |
300 fp->uf_flags = flags; | 303 fp->uf_flags = flags; |
301 fp->uf_calls = 0; | 304 fp->uf_calls = 0; |
302 fp->uf_script_ID = current_SID; | 305 fp->uf_script_ID = current_SID; |
303 | 306 |
686 dict_T *selfdict) /* Dictionary for "self" */ | 689 dict_T *selfdict) /* Dictionary for "self" */ |
687 { | 690 { |
688 char_u *save_sourcing_name; | 691 char_u *save_sourcing_name; |
689 linenr_T save_sourcing_lnum; | 692 linenr_T save_sourcing_lnum; |
690 scid_T save_current_SID; | 693 scid_T save_current_SID; |
694 int using_sandbox = FALSE; | |
691 funccall_T *fc; | 695 funccall_T *fc; |
692 int save_did_emsg; | 696 int save_did_emsg; |
693 static int depth = 0; | 697 static int depth = 0; |
694 dictitem_T *v; | 698 dictitem_T *v; |
695 int fixvar_idx = 0; /* index in fixvar[] */ | 699 int fixvar_idx = 0; /* index in fixvar[] */ |
852 /* Don't redraw while executing the function. */ | 856 /* Don't redraw while executing the function. */ |
853 ++RedrawingDisabled; | 857 ++RedrawingDisabled; |
854 save_sourcing_name = sourcing_name; | 858 save_sourcing_name = sourcing_name; |
855 save_sourcing_lnum = sourcing_lnum; | 859 save_sourcing_lnum = sourcing_lnum; |
856 sourcing_lnum = 1; | 860 sourcing_lnum = 1; |
861 | |
862 if (fp->uf_flags & FC_SANDBOX) | |
863 { | |
864 using_sandbox = TRUE; | |
865 ++sandbox; | |
866 } | |
867 | |
857 /* need space for function name + ("function " + 3) or "[number]" */ | 868 /* need space for function name + ("function " + 3) or "[number]" */ |
858 len = (save_sourcing_name == NULL ? 0 : STRLEN(save_sourcing_name)) | 869 len = (save_sourcing_name == NULL ? 0 : STRLEN(save_sourcing_name)) |
859 + STRLEN(fp->uf_name) + 20; | 870 + STRLEN(fp->uf_name) + 20; |
860 sourcing_name = alloc((unsigned)len); | 871 sourcing_name = alloc((unsigned)len); |
861 if (sourcing_name != NULL) | 872 if (sourcing_name != NULL) |
1018 current_SID = save_current_SID; | 1029 current_SID = save_current_SID; |
1019 #ifdef FEAT_PROFILE | 1030 #ifdef FEAT_PROFILE |
1020 if (do_profiling == PROF_YES) | 1031 if (do_profiling == PROF_YES) |
1021 script_prof_restore(&wait_start); | 1032 script_prof_restore(&wait_start); |
1022 #endif | 1033 #endif |
1034 if (using_sandbox) | |
1035 --sandbox; | |
1023 | 1036 |
1024 if (p_verbose >= 12 && sourcing_name != NULL) | 1037 if (p_verbose >= 12 && sourcing_name != NULL) |
1025 { | 1038 { |
1026 ++no_wait_return; | 1039 ++no_wait_return; |
1027 verbose_enter_scroll(); | 1040 verbose_enter_scroll(); |
2427 fp->uf_profiling = FALSE; | 2440 fp->uf_profiling = FALSE; |
2428 if (prof_def_func()) | 2441 if (prof_def_func()) |
2429 func_do_profile(fp); | 2442 func_do_profile(fp); |
2430 #endif | 2443 #endif |
2431 fp->uf_varargs = varargs; | 2444 fp->uf_varargs = varargs; |
2445 if (sandbox) | |
2446 flags |= FC_SANDBOX; | |
2432 fp->uf_flags = flags; | 2447 fp->uf_flags = flags; |
2433 fp->uf_calls = 0; | 2448 fp->uf_calls = 0; |
2434 fp->uf_script_ID = current_SID; | 2449 fp->uf_script_ID = current_SID; |
2435 goto ret_free; | 2450 goto ret_free; |
2436 | 2451 |