runtime: don't execute external commands when loading ftplugins

This is a followup to 816fbcc262 (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>
This commit is contained in:
Christian Brabandt
2023-09-06 20:41:25 +02:00
parent 1689e847ff
commit f7ac0ef509
6 changed files with 46 additions and 18 deletions

View File

@ -40,17 +40,17 @@ endif
let &l:define='\v(<fn>|<const>|<var>|^\s*\#\s*define)'
" Safety check: don't execute zip from current directory
let s:tmp_cwd = getcwd()
if !exists('g:zig_std_dir') && exists('*json_decode') &&
\ executable('zig') && (fnamemodify(exepath("zig"), ":p:h") != s:tmp_cwd
\ || (index(split($PATH,has("win32")? ';' : ':'), s:tmp_cwd) != -1 && s:tmp_cwd != '.'))
\ executable('zig') && get(g:, 'zig_exec', get(g:, 'plugin_exec', 0))
\ && (fnamemodify(exepath("zig"), ":p:h") != s:tmp_cwd
\ || (index(split($PATH,has("win32")? ';' : ':'), s:tmp_cwd) != -1 && s:tmp_cwd != '.'))
silent let s:env = system('zig env')
if v:shell_error == 0
let g:zig_std_dir = json_decode(s:env)['std_dir']
endif
unlet! s:env
endif
unlet s:tmp_cwd
unlet! s:tmp_cwd
if exists('g:zig_std_dir')
let &l:path = &l:path . ',' . g:zig_std_dir