0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

runtime(dist): verify that executable is in $PATH

Otherwise, if the executable to be verified does not exist,
this would cause a false-positive in the 'IsSafeExecutable()' check,
because 'exepath(executable)' returns an empty string and
'fnamemodify('', ':p:h')' returns the current directory and as a result
the 'IsSafeExecutable()' returns false (for the wrong reason).

Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Christian Brabandt 2024-08-17 15:52:11 +02:00
parent a4aa97590b
commit 8e25d91cb7
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
2 changed files with 8 additions and 0 deletions

View File

@ -18,6 +18,10 @@ endif
if !has('vim9script')
function dist#vim#IsSafeExecutable(filetype, executable)
let cwd = getcwd()
if empty(exepath(a:executable))
echomsg a:executable .. " not found in $PATH"
return v:false
endif
return get(g:, a:filetype .. '_exec', get(g:, 'plugin_exec', 0)) &&
\ (fnamemodify(exepath(a:executable), ':p:h') !=# cwd
\ || (split($PATH, has('win32') ? ';' : ':')->index(cwd) != -1 &&

View File

@ -6,6 +6,10 @@ vim9script
# Last Change: 2023 Oct 25
export def IsSafeExecutable(filetype: string, executable: string): bool
if empty(exepath(executable))
echomsg executable .. " not found in $PATH"
return v:false
endif
var cwd = getcwd()
return get(g:, filetype .. '_exec', get(g:, 'plugin_exec', 0))
&& (fnamemodify(exepath(executable), ':p:h') !=# cwd