runtime: don't execute external commands when loading ftplugins
This is a followup to 816fbcc262687b81fc46f82f7bbeb1453addfe0c (patch
9.0.1833: [security] runtime file fixes)
It basically disables that external commands are run on loading of the
filetype plugin, **unless** the user has set the `g:plugin_exec = 1`
global variable in their configuration or for a specific filetype the
variable g:<filetype>_exec=1.
There are a few more plugins, that may execute system commands like
debchangelog, gitcommit, sh, racket, zsh, ps1 but those do at least
do not run those commands by default during loading of the filetype plugin
(there the command is mostly run as convenience for auto-completion or
to provide documentation lookup).
closes: #13034
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Tim Pope <vim@tpope.org>
diff --git a/runtime/ftplugin/perl.vim b/runtime/ftplugin/perl.vim
index 4361097..f3de81d 100644
--- a/runtime/ftplugin/perl.vim
+++ b/runtime/ftplugin/perl.vim
@@ -54,10 +54,12 @@
" Set this once, globally.
if !exists("perlpath")
- " safety check: don't execute perl from current directory
let s:tmp_cwd = getcwd()
- if executable("perl") && (fnamemodify(exepath("perl"), ":p:h") != s:tmp_cwd
- \ || (index(split($PATH,has("win32")? ';' : ':'), s:tmp_cwd) != -1 && s:tmp_cwd != '.'))
+ " safety check: don't execute perl binary by default
+ if executable("perl") && get(g:, 'perl_exec', get(g:, 'plugin_exec', 0))
+ \ && (fnamemodify(exepath("perl"), ":p:h") != s:tmp_cwd
+ \ || (index(split($PATH, has("win32") ? ';' : ':'), s:tmp_cwd) != -1
+ \ && s:tmp_cwd != '.'))
try
if &shellxquote != '"'
let perlpath = system('perl -e "print join(q/,/,@INC)"')
@@ -73,7 +75,7 @@
" current directory and the directory of the current file.
let perlpath = ".,,"
endif
- unlet s:tmp_cwd
+ unlet! s:tmp_cwd
endif
" Append perlpath to the existing path value, if it is set. Since we don't