changeset 35987:465d9dc26f01

runtime(dist): verify that executable is in $PATH Commit: https://github.com/vim/vim/commit/8e25d91cb7bb4dc171cb4e95b1bb79a39400a13a Author: Christian Brabandt <cb@256bit.org> Date: Sat Aug 17 15:52:11 2024 +0200 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>
author Christian Brabandt <cb@256bit.org>
date Sat, 17 Aug 2024 21:15:02 +0200
parents b2f327ddee2a
children b0f387263687
files runtime/autoload/dist/vim.vim runtime/autoload/dist/vim9.vim
diffstat 2 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/runtime/autoload/dist/vim.vim
+++ b/runtime/autoload/dist/vim.vim
@@ -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 &&
--- a/runtime/autoload/dist/vim9.vim
+++ b/runtime/autoload/dist/vim9.vim
@@ -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