Patch 8.2.4860

26 views
Skip to first unread message

Bram Moolenaar

unread,
May 3, 2022, 6:03:17 AM5/3/22
to vim...@googlegroups.com

Patch 8.2.4860
Problem: MS-Windows: always uses current directory for executables.
Solution: Check the NoDefaultCurrentDirectoryInExePath environment variable.
(Yasuhiro Matsumoto, closes #10341)
Files: runtime/doc/builtin.txt, src/os_win32.c,
src/testdir/test_functions.vim


*** ../vim-8.2.4859/runtime/doc/builtin.txt 2022-04-28 15:26:29.210947840 +0100
--- runtime/doc/builtin.txt 2022-05-03 11:00:20.822947244 +0100
***************
*** 2013,2020 ****
On MS-Windows it only checks if the file exists and is not a
directory, not if it's really executable.
On MS-Windows an executable in the same directory as Vim is
! always found. Since this directory is added to $PATH it
! should also work to execute it |win32-PATH|.
The result is a Number:
1 exists
0 does not exist
--- 2016,2025 ----
On MS-Windows it only checks if the file exists and is not a
directory, not if it's really executable.
On MS-Windows an executable in the same directory as Vim is
! normally found. Since this directory is added to $PATH it
! should also work to execute it |win32-PATH|. This can be
! disabled by setting the $NoDefaultCurrentDirectoryInExePath
! environment variable. *NoDefaultCurrentDirectoryInExePath*
The result is a Number:
1 exists
0 does not exist
*** ../vim-8.2.4859/src/os_win32.c 2022-04-12 15:08:36.673207621 +0100
--- src/os_win32.c 2022-05-03 10:54:13.823359629 +0100
***************
*** 2237,2243 ****
retval = FALSE;
goto theend;
}
! STRCPY(pathbuf, ".;");
STRCAT(pathbuf, p);
}
}
--- 2237,2247 ----
retval = FALSE;
goto theend;
}
!
! if (mch_getenv("NoDefaultCurrentDirectoryInExePath") == NULL)
! STRCPY(pathbuf, ".;");
! else
! *pathbuf = NUL;
STRCAT(pathbuf, p);
}
}
***************
*** 2411,2417 ****
* Otherwise the default "findstr /n" is used.
*/
if (!executable_exists("findstr.exe", NULL, TRUE, FALSE))
! set_option_value((char_u *)"grepprg", 0, (char_u *)"grep -n", 0);

# ifdef FEAT_CLIPBOARD
win_clip_init();
--- 2415,2422 ----
* Otherwise the default "findstr /n" is used.
*/
if (!executable_exists("findstr.exe", NULL, TRUE, FALSE))
! set_option_value_give_err((char_u *)"grepprg",
! 0, (char_u *)"grep -n", 0);

# ifdef FEAT_CLIPBOARD
win_clip_init();
*** ../vim-8.2.4859/src/testdir/test_functions.vim 2022-05-02 22:53:41.384211031 +0100
--- src/testdir/test_functions.vim 2022-05-03 10:54:13.823359629 +0100
***************
*** 2906,2909 ****
--- 2906,2927 ----
endif
endfunc

+ " Test for exepath()
+ func Test_exepath()
+ if has('win32')
+ call assert_notequal(exepath('cmd'), '')
+
+ let oldNoDefaultCurrentDirectoryInExePath = $NoDefaultCurrentDirectoryInExePath
+ call writefile(['@echo off', 'echo Evil'], 'vim-test-evil.bat')
+ let $NoDefaultCurrentDirectoryInExePath = ''
+ call assert_notequal(exepath("vim-test-evil.bat"), '')
+ let $NoDefaultCurrentDirectoryInExePath = '1'
+ call assert_equal(exepath("vim-test-evil.bat"), '')
+ let $NoDefaultCurrentDirectoryInExePath = oldNoDefaultCurrentDirectoryInExePath
+ call delete('vim-test-evil.bat')
+ else
+ call assert_notequal(exepath('sh'), '')
+ endif
+ endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.4859/src/version.c 2022-05-02 23:50:24.389602160 +0100
--- src/version.c 2022-05-03 10:57:21.243157672 +0100
***************
*** 748,749 ****
--- 748,751 ----
{ /* Add new patch number below this line */
+ /**/
+ 4860,
/**/

--
There's no place like $(HOME)!

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

James McCoy

unread,
May 3, 2022, 8:02:07 PM5/3/22
to vim...@googlegroups.com
Shouldn't the default behavior be NOT to add that directory to the
path? If a user really wants to add Vim's directory to their path, they
already have a means to do that -- their vimrc. Why should Vim be doing
it?

Cheers,
--
James
GPG Key: 4096R/91BF BF4D 6956 BD5D F7B7 2D23 DFE6 91AE 331B A3DB

Bram Moolenaar

unread,
May 4, 2022, 8:28:51 AM5/4/22
to vim...@googlegroups.com, James McCoy
This is how MS-Windows works by default. For example, if you build Vim,
resulting in vim.exe, then typing "vim" will find vim.exe in the current
directory. Many users depend on this.

Obviously this is a trojan horse security issue, which is why on
Unix-like systems adding dot to $PATH is very unusual or generates
warnings.

Apparently using the $NoDefaultCurrentDirectoryInExePath environment
variable is the standard way how later MS-Windows "solved" this. So Vim
should respect it.

--
I AM THANKFUL...
...for a lawn that needs mowing, windows that need cleaning
and gutters that need fixing because it means I have a home.

James McCoy

unread,
May 4, 2022, 8:41:29 AM5/4/22
to vim...@googlegroups.com
On Wed, May 04, 2022 at 01:28:45PM +0100, Bram Moolenaar wrote:
> Apparently using the $NoDefaultCurrentDirectoryInExePath environment
> variable is the standard way how later MS-Windows "solved" this. So Vim
> should respect it.

Ah, I was missing the bit that $NoDefaultCurrentDirectoryInExePath was a
standard Windows thing. Thanks!
Reply all
Reply to author
Forward
0 new messages