|
|
30d063 |
diff --git a/runtime/doc/starting.txt b/runtime/doc/starting.txt
|
|
|
30d063 |
index 8256152..8320039 100644
|
|
|
30d063 |
--- a/runtime/doc/starting.txt
|
|
|
30d063 |
+++ b/runtime/doc/starting.txt
|
|
|
30d063 |
@@ -247,12 +247,18 @@ a slash. Thus "-R" means recovery and "-/R" readonly.
|
|
|
30d063 |
changes and writing.
|
|
|
30d063 |
{not in Vi}
|
|
|
30d063 |
|
|
|
30d063 |
- *-Z* *restricted-mode* *E145*
|
|
|
30d063 |
+ *-Z* *restricted-mode* *E145* *E981*
|
|
|
30d063 |
-Z Restricted mode. All commands that make use of an external
|
|
|
30d063 |
shell are disabled. This includes suspending with CTRL-Z,
|
|
|
30d063 |
- ":sh", filtering, the system() function, backtick expansion,
|
|
|
30d063 |
- delete(), rename(), mkdir(), writefile(), libcall(),
|
|
|
30d063 |
- job_start(), etc.
|
|
|
30d063 |
+ ":sh", filtering, the system() function, backtick expansion
|
|
|
30d063 |
+ and libcall().
|
|
|
30d063 |
+ Also disallowed are delete(), rename(), mkdir(), job_start(),
|
|
|
30d063 |
+ etc.
|
|
|
30d063 |
+ Interfaces, such as Python, Ruby and Lua, are also disabled,
|
|
|
30d063 |
+ since they could be used to execute shell commands. Perl uses
|
|
|
30d063 |
+ the Safe module.
|
|
|
30d063 |
+ Note that the user may still find a loophole to execute a
|
|
|
30d063 |
+ shell command, it has only been made difficult.
|
|
|
30d063 |
{not in Vi}
|
|
|
30d063 |
|
|
|
30d063 |
*-g*
|
|
|
30d063 |
diff --git a/src/evalfunc.c b/src/evalfunc.c
|
|
|
30d063 |
index dd4462d..3cc305a 100644
|
|
|
30d063 |
--- a/src/evalfunc.c
|
|
|
30d063 |
+++ b/src/evalfunc.c
|
|
|
30d063 |
@@ -6446,7 +6446,7 @@ f_histadd(typval_T *argvars UNUSED, typval_T *rettv)
|
|
|
30d063 |
#endif
|
|
|
30d063 |
|
|
|
30d063 |
rettv->vval.v_number = FALSE;
|
|
|
30d063 |
- if (check_restricted() || check_secure())
|
|
|
30d063 |
+ if (check_secure())
|
|
|
30d063 |
return;
|
|
|
30d063 |
#ifdef FEAT_CMDHIST
|
|
|
30d063 |
str = get_tv_string_chk(&argvars[0]); /* NULL on type error */
|
|
|
30d063 |
@@ -7456,6 +7456,9 @@ f_luaeval(typval_T *argvars, typval_T *rettv)
|
|
|
30d063 |
char_u *str;
|
|
|
30d063 |
char_u buf[NUMBUFLEN];
|
|
|
30d063 |
|
|
|
30d063 |
+ if (check_restricted() || check_secure())
|
|
|
30d063 |
+ return;
|
|
|
30d063 |
+
|
|
|
30d063 |
str = get_tv_string_buf(&argvars[0], buf);
|
|
|
30d063 |
do_luaeval(str, argvars + 1, rettv);
|
|
|
30d063 |
}
|
|
|
30d063 |
@@ -8188,6 +8191,8 @@ f_mzeval(typval_T *argvars, typval_T *rettv)
|
|
|
30d063 |
char_u *str;
|
|
|
30d063 |
char_u buf[NUMBUFLEN];
|
|
|
30d063 |
|
|
|
30d063 |
+ if (check_restricted() || check_secure())
|
|
|
30d063 |
+ return;
|
|
|
30d063 |
str = get_tv_string_buf(&argvars[0], buf);
|
|
|
30d063 |
do_mzeval(str, rettv);
|
|
|
30d063 |
}
|
|
|
30d063 |
@@ -8398,6 +8403,9 @@ f_py3eval(typval_T *argvars, typval_T *rettv)
|
|
|
30d063 |
char_u *str;
|
|
|
30d063 |
char_u buf[NUMBUFLEN];
|
|
|
30d063 |
|
|
|
30d063 |
+ if (check_restricted() || check_secure())
|
|
|
30d063 |
+ return;
|
|
|
30d063 |
+
|
|
|
30d063 |
if (p_pyx == 0)
|
|
|
30d063 |
p_pyx = 3;
|
|
|
30d063 |
|
|
|
30d063 |
@@ -8416,6 +8424,9 @@ f_pyeval(typval_T *argvars, typval_T *rettv)
|
|
|
30d063 |
char_u *str;
|
|
|
30d063 |
char_u buf[NUMBUFLEN];
|
|
|
30d063 |
|
|
|
30d063 |
+ if (check_restricted() || check_secure())
|
|
|
30d063 |
+ return;
|
|
|
30d063 |
+
|
|
|
30d063 |
if (p_pyx == 0)
|
|
|
30d063 |
p_pyx = 2;
|
|
|
30d063 |
|
|
|
30d063 |
@@ -8431,6 +8442,9 @@ f_pyeval(typval_T *argvars, typval_T *rettv)
|
|
|
30d063 |
static void
|
|
|
30d063 |
f_pyxeval(typval_T *argvars, typval_T *rettv)
|
|
|
30d063 |
{
|
|
|
30d063 |
+ if (check_restricted() || check_secure())
|
|
|
30d063 |
+ return;
|
|
|
30d063 |
+
|
|
|
30d063 |
# if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
|
|
|
30d063 |
init_pyxversion();
|
|
|
30d063 |
if (p_pyx == 2)
|
|
|
30d063 |
@@ -10272,7 +10286,7 @@ f_setbufvar(typval_T *argvars, typval_T *rettv UNUSED)
|
|
|
30d063 |
typval_T *varp;
|
|
|
30d063 |
char_u nbuf[NUMBUFLEN];
|
|
|
30d063 |
|
|
|
30d063 |
- if (check_restricted() || check_secure())
|
|
|
30d063 |
+ if (check_secure())
|
|
|
30d063 |
return;
|
|
|
30d063 |
(void)get_tv_number(&argvars[0]); /* issue errmsg if type error */
|
|
|
30d063 |
varname = get_tv_string_chk(&argvars[1]);
|
|
|
30d063 |
@@ -10792,7 +10806,7 @@ f_settabvar(typval_T *argvars, typval_T *rettv)
|
|
|
30d063 |
|
|
|
30d063 |
rettv->vval.v_number = 0;
|
|
|
30d063 |
|
|
|
30d063 |
- if (check_restricted() || check_secure())
|
|
|
30d063 |
+ if (check_secure())
|
|
|
30d063 |
return;
|
|
|
30d063 |
|
|
|
30d063 |
tp = find_tabpage((int)get_tv_number_chk(&argvars[0], NULL));
|
|
|
30d063 |
@@ -13674,7 +13688,7 @@ f_writefile(typval_T *argvars, typval_T *rettv)
|
|
|
30d063 |
list_T *list;
|
|
|
30d063 |
|
|
|
30d063 |
rettv->vval.v_number = -1;
|
|
|
30d063 |
- if (check_restricted() || check_secure())
|
|
|
30d063 |
+ if (check_secure())
|
|
|
30d063 |
return;
|
|
|
30d063 |
|
|
|
30d063 |
if (argvars[0].v_type != VAR_LIST)
|
|
|
30d063 |
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
|
|
|
30d063 |
index 111fe01..1827fec 100644
|
|
|
30d063 |
--- a/src/ex_cmds.c
|
|
|
30d063 |
+++ b/src/ex_cmds.c
|
|
|
30d063 |
@@ -4693,7 +4693,7 @@ check_restricted(void)
|
|
|
30d063 |
{
|
|
|
30d063 |
if (restricted)
|
|
|
30d063 |
{
|
|
|
30d063 |
- EMSG(_("E145: Shell commands not allowed in rvim"));
|
|
|
30d063 |
+ EMSG(_("E145: Shell commands and some functionality not allowed in rvim"));
|
|
|
30d063 |
return TRUE;
|
|
|
30d063 |
}
|
|
|
30d063 |
return FALSE;
|
|
|
30d063 |
diff --git a/src/ex_cmds.h b/src/ex_cmds.h
|
|
|
30d063 |
index 48b0253..82d6e29 100644
|
|
|
30d063 |
--- a/src/ex_cmds.h
|
|
|
30d063 |
+++ b/src/ex_cmds.h
|
|
|
30d063 |
@@ -56,6 +56,7 @@
|
|
|
30d063 |
* curbuf_lock is set */
|
|
|
30d063 |
#define MODIFY 0x200000L /* forbidden in non-'modifiable' buffer */
|
|
|
30d063 |
#define EXFLAGS 0x400000L /* allow flags after count in argument */
|
|
|
30d063 |
+#define RESTRICT 0x800000L /* forbidden in restricted mode */
|
|
|
30d063 |
#define FILES (XFILE | EXTRA) /* multiple extra files allowed */
|
|
|
30d063 |
#define WORD1 (EXTRA | NOSPC) /* one extra word allowed */
|
|
|
30d063 |
#define FILE1 (FILES | NOSPC) /* 1 file allowed, defaults to current file */
|
|
|
30d063 |
@@ -860,13 +861,13 @@ EX(CMD_lunmap, "lunmap", ex_unmap,
|
|
|
30d063 |
EXTRA|TRLBAR|NOTRLCOM|USECTRLV|CMDWIN,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_lua, "lua", ex_lua,
|
|
|
30d063 |
- RANGE|EXTRA|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|EXTRA|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_luado, "luado", ex_luado,
|
|
|
30d063 |
- RANGE|DFLALL|EXTRA|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|DFLALL|EXTRA|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_luafile, "luafile", ex_luafile,
|
|
|
30d063 |
- RANGE|FILE1|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|FILE1|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_lvimgrep, "lvimgrep", ex_vimgrep,
|
|
|
30d063 |
RANGE|NOTADR|BANG|NEEDARG|EXTRA|NOTRLCOM|TRLBAR|XFILE,
|
|
|
30d063 |
@@ -929,10 +930,10 @@ EX(CMD_mode, "mode", ex_mode,
|
|
|
30d063 |
WORD1|TRLBAR|CMDWIN,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_mzscheme, "mzscheme", ex_mzscheme,
|
|
|
30d063 |
- RANGE|EXTRA|DFLALL|NEEDARG|CMDWIN|SBOXOK,
|
|
|
30d063 |
+ RANGE|EXTRA|DFLALL|NEEDARG|CMDWIN|SBOXOK|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_mzfile, "mzfile", ex_mzfile,
|
|
|
30d063 |
- RANGE|FILE1|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|FILE1|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_next, "next", ex_next,
|
|
|
30d063 |
RANGE|NOTADR|BANG|FILES|EDITCMD|ARGOPT|TRLBAR,
|
|
|
30d063 |
@@ -1115,37 +1116,37 @@ EX(CMD_pwd, "pwd", ex_pwd,
|
|
|
30d063 |
TRLBAR|CMDWIN,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_python, "python", ex_python,
|
|
|
30d063 |
- RANGE|EXTRA|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|EXTRA|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_pydo, "pydo", ex_pydo,
|
|
|
30d063 |
- RANGE|DFLALL|EXTRA|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|DFLALL|EXTRA|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_pyfile, "pyfile", ex_pyfile,
|
|
|
30d063 |
- RANGE|FILE1|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|FILE1|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_py3, "py3", ex_py3,
|
|
|
30d063 |
- RANGE|EXTRA|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|EXTRA|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_py3do, "py3do", ex_py3do,
|
|
|
30d063 |
- RANGE|DFLALL|EXTRA|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|DFLALL|EXTRA|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_python3, "python3", ex_py3,
|
|
|
30d063 |
- RANGE|EXTRA|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|EXTRA|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_py3file, "py3file", ex_py3file,
|
|
|
30d063 |
- RANGE|FILE1|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|FILE1|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_pyx, "pyx", ex_pyx,
|
|
|
30d063 |
- RANGE|EXTRA|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|EXTRA|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_pyxdo, "pyxdo", ex_pyxdo,
|
|
|
30d063 |
- RANGE|DFLALL|EXTRA|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|DFLALL|EXTRA|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_pythonx, "pythonx", ex_pyx,
|
|
|
30d063 |
- RANGE|EXTRA|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|EXTRA|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_pyxfile, "pyxfile", ex_pyxfile,
|
|
|
30d063 |
- RANGE|FILE1|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|FILE1|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_quit, "quit", ex_quit,
|
|
|
30d063 |
BANG|RANGE|COUNT|NOTADR|TRLBAR|CMDWIN,
|
|
|
30d063 |
@@ -1199,13 +1200,13 @@ EX(CMD_runtime, "runtime", ex_runtime,
|
|
|
30d063 |
BANG|NEEDARG|FILES|TRLBAR|SBOXOK|CMDWIN,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_ruby, "ruby", ex_ruby,
|
|
|
30d063 |
- RANGE|EXTRA|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|EXTRA|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_rubydo, "rubydo", ex_rubydo,
|
|
|
30d063 |
- RANGE|DFLALL|EXTRA|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|DFLALL|EXTRA|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_rubyfile, "rubyfile", ex_rubyfile,
|
|
|
30d063 |
- RANGE|FILE1|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|FILE1|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_rundo, "rundo", ex_rundo,
|
|
|
30d063 |
NEEDARG|FILE1,
|
|
|
30d063 |
@@ -1472,13 +1473,13 @@ EX(CMD_tabs, "tabs", ex_tabs,
|
|
|
30d063 |
TRLBAR|CMDWIN,
|
|
|
30d063 |
ADDR_TABS),
|
|
|
30d063 |
EX(CMD_tcl, "tcl", ex_tcl,
|
|
|
30d063 |
- RANGE|EXTRA|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|EXTRA|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_tcldo, "tcldo", ex_tcldo,
|
|
|
30d063 |
- RANGE|DFLALL|EXTRA|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|DFLALL|EXTRA|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_tclfile, "tclfile", ex_tclfile,
|
|
|
30d063 |
- RANGE|FILE1|NEEDARG|CMDWIN,
|
|
|
30d063 |
+ RANGE|FILE1|NEEDARG|CMDWIN|RESTRICT,
|
|
|
30d063 |
ADDR_LINES),
|
|
|
30d063 |
EX(CMD_tearoff, "tearoff", ex_tearoff,
|
|
|
30d063 |
NEEDARG|EXTRA|TRLBAR|NOTRLCOM|CMDWIN,
|
|
|
30d063 |
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
|
|
|
30d063 |
index ef86fc8..aaf2f9d 100644
|
|
|
30d063 |
--- a/src/ex_docmd.c
|
|
|
30d063 |
+++ b/src/ex_docmd.c
|
|
|
30d063 |
@@ -2372,11 +2372,16 @@ do_one_cmd(
|
|
|
30d063 |
#ifdef HAVE_SANDBOX
|
|
|
30d063 |
if (sandbox != 0 && !(ea.argt & SBOXOK))
|
|
|
30d063 |
{
|
|
|
30d063 |
- /* Command not allowed in sandbox. */
|
|
|
30d063 |
+ // Command not allowed in sandbox.
|
|
|
30d063 |
errormsg = (char_u *)_(e_sandbox);
|
|
|
30d063 |
goto doend;
|
|
|
30d063 |
}
|
|
|
30d063 |
#endif
|
|
|
30d063 |
+ if (restricted != 0 && (ea.argt & RESTRICT))
|
|
|
30d063 |
+ {
|
|
|
30d063 |
+ errormsg = (char_u *)_("E981: Command not allowed in rvim");
|
|
|
30d063 |
+ goto doend;
|
|
|
30d063 |
+ }
|
|
|
30d063 |
if (!curbuf->b_p_ma && (ea.argt & MODIFY))
|
|
|
30d063 |
{
|
|
|
30d063 |
/* Command not allowed in non-'modifiable' buffer */
|
|
|
30d063 |
diff --git a/src/if_perl.xs b/src/if_perl.xs
|
|
|
30d063 |
index 7b45033..fc8d613 100644
|
|
|
30d063 |
--- a/src/if_perl.xs
|
|
|
30d063 |
+++ b/src/if_perl.xs
|
|
|
30d063 |
@@ -930,6 +930,7 @@ VIM_init(void)
|
|
|
30d063 |
#ifdef DYNAMIC_PERL
|
|
|
30d063 |
static char *e_noperl = N_("Sorry, this command is disabled: the Perl library could not be loaded.");
|
|
|
30d063 |
#endif
|
|
|
30d063 |
+static char *e_perlsandbox = N_("E299: Perl evaluation forbidden in sandbox without the Safe module");
|
|
|
30d063 |
|
|
|
30d063 |
/*
|
|
|
30d063 |
* ":perl"
|
|
|
30d063 |
@@ -978,13 +979,12 @@ ex_perl(exarg_T *eap)
|
|
|
30d063 |
vim_free(script);
|
|
|
30d063 |
}
|
|
|
30d063 |
|
|
|
30d063 |
-#ifdef HAVE_SANDBOX
|
|
|
30d063 |
- if (sandbox)
|
|
|
30d063 |
+ if (sandbox || secure)
|
|
|
30d063 |
{
|
|
|
30d063 |
safe = perl_get_sv("VIM::safe", FALSE);
|
|
|
30d063 |
# ifndef MAKE_TEST /* avoid a warning for unreachable code */
|
|
|
30d063 |
if (safe == NULL || !SvTRUE(safe))
|
|
|
30d063 |
- EMSG(_("E299: Perl evaluation forbidden in sandbox without the Safe module"));
|
|
|
30d063 |
+ EMSG(_(e_perlsandbox));
|
|
|
30d063 |
else
|
|
|
30d063 |
# endif
|
|
|
30d063 |
{
|
|
|
30d063 |
@@ -996,7 +996,6 @@ ex_perl(exarg_T *eap)
|
|
|
30d063 |
}
|
|
|
30d063 |
}
|
|
|
30d063 |
else
|
|
|
30d063 |
-#endif
|
|
|
30d063 |
perl_eval_sv(sv, G_DISCARD | G_NOARGS);
|
|
|
30d063 |
|
|
|
30d063 |
SvREFCNT_dec(sv);
|
|
|
30d063 |
@@ -1259,13 +1258,12 @@ do_perleval(char_u *str, typval_T *rettv)
|
|
|
30d063 |
ENTER;
|
|
|
30d063 |
SAVETMPS;
|
|
|
30d063 |
|
|
|
30d063 |
-#ifdef HAVE_SANDBOX
|
|
|
30d063 |
- if (sandbox)
|
|
|
30d063 |
+ if (sandbox || secure)
|
|
|
30d063 |
{
|
|
|
30d063 |
safe = get_sv("VIM::safe", FALSE);
|
|
|
30d063 |
# ifndef MAKE_TEST /* avoid a warning for unreachable code */
|
|
|
30d063 |
if (safe == NULL || !SvTRUE(safe))
|
|
|
30d063 |
- EMSG(_("E299: Perl evaluation forbidden in sandbox without the Safe module"));
|
|
|
30d063 |
+ EMSG(_(e_perlsandbox));
|
|
|
30d063 |
else
|
|
|
30d063 |
# endif
|
|
|
30d063 |
{
|
|
|
30d063 |
@@ -1281,7 +1279,6 @@ do_perleval(char_u *str, typval_T *rettv)
|
|
|
30d063 |
}
|
|
|
30d063 |
}
|
|
|
30d063 |
else
|
|
|
30d063 |
-#endif /* HAVE_SANDBOX */
|
|
|
30d063 |
sv = eval_pv((char *)str, 0);
|
|
|
30d063 |
|
|
|
30d063 |
if (sv) {
|
|
|
30d063 |
diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak
|
|
|
30d063 |
index e36089a..5f1c38c 100644
|
|
|
30d063 |
--- a/src/testdir/Make_all.mak
|
|
|
30d063 |
+++ b/src/testdir/Make_all.mak
|
|
|
30d063 |
@@ -156,6 +156,7 @@ NEW_TESTS = test_arabic.res \
|
|
|
30d063 |
test_quotestar.res \
|
|
|
30d063 |
test_regex_char_classes.res \
|
|
|
30d063 |
test_registers.res \
|
|
|
30d063 |
+ test_restricted.res \
|
|
|
30d063 |
test_retab.res \
|
|
|
30d063 |
test_ruby.res \
|
|
|
30d063 |
test_scrollbind.res \
|
|
|
30d063 |
diff --git a/src/testdir/test_restricted.vim b/src/testdir/test_restricted.vim
|
|
|
30d063 |
new file mode 100644
|
|
|
30d063 |
index 0000000..9dd937c
|
|
|
30d063 |
--- /dev/null
|
|
|
30d063 |
+++ b/src/testdir/test_restricted.vim
|
|
|
30d063 |
@@ -0,0 +1,107 @@
|
|
|
30d063 |
+" Test for "rvim" or "vim -Z"
|
|
|
30d063 |
+
|
|
|
30d063 |
+source shared.vim
|
|
|
30d063 |
+
|
|
|
30d063 |
+func Test_restricted()
|
|
|
30d063 |
+ let cmd = GetVimCommand('Xrestricted')
|
|
|
30d063 |
+ if cmd == ''
|
|
|
30d063 |
+ return
|
|
|
30d063 |
+ endif
|
|
|
30d063 |
+
|
|
|
30d063 |
+ call writefile([
|
|
|
30d063 |
+ \ "silent !ls",
|
|
|
30d063 |
+ \ "call writefile([v:errmsg], 'Xrestrout')",
|
|
|
30d063 |
+ \ "qa!",
|
|
|
30d063 |
+ \ ], 'Xrestricted')
|
|
|
30d063 |
+ call system(cmd . ' -Z')
|
|
|
30d063 |
+ call assert_match('E145:', join(readfile('Xrestrout')))
|
|
|
30d063 |
+
|
|
|
30d063 |
+ call delete('Xrestricted')
|
|
|
30d063 |
+ call delete('Xrestrout')
|
|
|
30d063 |
+endfunc
|
|
|
30d063 |
+
|
|
|
30d063 |
+func Run_restricted_test(ex_cmd, error)
|
|
|
30d063 |
+ let cmd = GetVimCommand('Xrestricted')
|
|
|
30d063 |
+ if cmd == ''
|
|
|
30d063 |
+ return
|
|
|
30d063 |
+ endif
|
|
|
30d063 |
+
|
|
|
30d063 |
+ call writefile([
|
|
|
30d063 |
+ \ a:ex_cmd,
|
|
|
30d063 |
+ \ "call writefile([v:errmsg], 'Xrestrout')",
|
|
|
30d063 |
+ \ "qa!",
|
|
|
30d063 |
+ \ ], 'Xrestricted')
|
|
|
30d063 |
+ call system(cmd . ' -Z')
|
|
|
30d063 |
+ call assert_match(a:error, join(readfile('Xrestrout')))
|
|
|
30d063 |
+
|
|
|
30d063 |
+ call delete('Xrestricted')
|
|
|
30d063 |
+ call delete('Xrestrout')
|
|
|
30d063 |
+endfunc
|
|
|
30d063 |
+
|
|
|
30d063 |
+func Test_restricted_lua()
|
|
|
30d063 |
+ if !has('lua')
|
|
|
30d063 |
+ throw 'Skipped: Lua is not supported'
|
|
|
30d063 |
+ endif
|
|
|
30d063 |
+ call Run_restricted_test('lua print("Hello, Vim!")', 'E981:')
|
|
|
30d063 |
+ call Run_restricted_test('luado return "hello"', 'E981:')
|
|
|
30d063 |
+ call Run_restricted_test('luafile somefile', 'E981:')
|
|
|
30d063 |
+ call Run_restricted_test('call luaeval("expression")', 'E145:')
|
|
|
30d063 |
+endfunc
|
|
|
30d063 |
+
|
|
|
30d063 |
+func Test_restricted_mzscheme()
|
|
|
30d063 |
+ if !has('mzscheme')
|
|
|
30d063 |
+ throw 'Skipped: MzScheme is not supported'
|
|
|
30d063 |
+ endif
|
|
|
30d063 |
+ call Run_restricted_test('mzscheme statement', 'E981:')
|
|
|
30d063 |
+ call Run_restricted_test('mzfile somefile', 'E981:')
|
|
|
30d063 |
+ call Run_restricted_test('call mzeval("expression")', 'E145:')
|
|
|
30d063 |
+endfunc
|
|
|
30d063 |
+
|
|
|
30d063 |
+func Test_restricted_perl()
|
|
|
30d063 |
+ if !has('perl')
|
|
|
30d063 |
+ throw 'Skipped: Perl is not supported'
|
|
|
30d063 |
+ endif
|
|
|
30d063 |
+ " TODO: how to make Safe mode fail?
|
|
|
30d063 |
+ " call Run_restricted_test('perl system("ls")', 'E981:')
|
|
|
30d063 |
+ " call Run_restricted_test('perldo system("hello")', 'E981:')
|
|
|
30d063 |
+ " call Run_restricted_test('perlfile somefile', 'E981:')
|
|
|
30d063 |
+ " call Run_restricted_test('call perleval("system(\"ls\")")', 'E145:')
|
|
|
30d063 |
+endfunc
|
|
|
30d063 |
+
|
|
|
30d063 |
+func Test_restricted_python()
|
|
|
30d063 |
+ if !has('python')
|
|
|
30d063 |
+ throw 'Skipped: Python is not supported'
|
|
|
30d063 |
+ endif
|
|
|
30d063 |
+ call Run_restricted_test('python print "hello"', 'E981:')
|
|
|
30d063 |
+ call Run_restricted_test('pydo return "hello"', 'E981:')
|
|
|
30d063 |
+ call Run_restricted_test('pyfile somefile', 'E981:')
|
|
|
30d063 |
+ call Run_restricted_test('call pyeval("expression")', 'E145:')
|
|
|
30d063 |
+endfunc
|
|
|
30d063 |
+
|
|
|
30d063 |
+func Test_restricted_python3()
|
|
|
30d063 |
+ if !has('python3')
|
|
|
30d063 |
+ throw 'Skipped: Python3 is not supported'
|
|
|
30d063 |
+ endif
|
|
|
30d063 |
+ call Run_restricted_test('py3 print "hello"', 'E981:')
|
|
|
30d063 |
+ call Run_restricted_test('py3do return "hello"', 'E981:')
|
|
|
30d063 |
+ call Run_restricted_test('py3file somefile', 'E981:')
|
|
|
30d063 |
+ call Run_restricted_test('call py3eval("expression")', 'E145:')
|
|
|
30d063 |
+endfunc
|
|
|
30d063 |
+
|
|
|
30d063 |
+func Test_restricted_ruby()
|
|
|
30d063 |
+ if !has('ruby')
|
|
|
30d063 |
+ throw 'Skipped: Ruby is not supported'
|
|
|
30d063 |
+ endif
|
|
|
30d063 |
+ call Run_restricted_test('ruby print "Hello"', 'E981:')
|
|
|
30d063 |
+ call Run_restricted_test('rubydo print "Hello"', 'E981:')
|
|
|
30d063 |
+ call Run_restricted_test('rubyfile somefile', 'E981:')
|
|
|
30d063 |
+endfunc
|
|
|
30d063 |
+
|
|
|
30d063 |
+func Test_restricted_tcl()
|
|
|
30d063 |
+ if !has('tcl')
|
|
|
30d063 |
+ throw 'Skipped: Tcl is not supported'
|
|
|
30d063 |
+ endif
|
|
|
30d063 |
+ call Run_restricted_test('tcl puts "Hello"', 'E981:')
|
|
|
30d063 |
+ call Run_restricted_test('tcldo puts "Hello"', 'E981:')
|
|
|
30d063 |
+ call Run_restricted_test('tclfile somefile', 'E981:')
|
|
|
30d063 |
+endfunc
|