Skip to content

Commit 839e81e

Browse files
committed
patch 8.1.0485: term_start() does not check if directory is accessible
Problem: term_start() does not check if directory is accessible. Solution: Add mch_access() call. (Jason Franklin)
1 parent 3865450 commit 839e81e

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/channel.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4916,7 +4916,8 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2)
49164916
if (!(supported2 & JO2_CWD))
49174917
break;
49184918
opt->jo_cwd = get_tv_string_buf_chk(item, opt->jo_cwd_buf);
4919-
if (opt->jo_cwd == NULL || !mch_isdir(opt->jo_cwd))
4919+
if (opt->jo_cwd == NULL || !mch_isdir(opt->jo_cwd)
4920+
|| mch_access((char *)opt->jo_cwd, X_OK) != 0)
49204921
{
49214922
EMSG2(_(e_invargval), "cwd");
49224923
return FAIL;

src/testdir/test_terminal.vim

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,28 @@ func Test_terminal_cwd()
478478
call delete('Xdir', 'rf')
479479
endfunc
480480

481+
func Test_terminal_cwd_failure()
482+
" Case 1: Provided directory is not actually a directory. Attempt to make
483+
" the file executable as well.
484+
call writefile([], 'Xfile')
485+
call setfperm('Xfile', 'rwx------')
486+
call assert_fails("call term_start(&shell, {'cwd': 'Xfile'})", 'E475:')
487+
call delete('Xfile')
488+
489+
" Case 2: Directory does not exist.
490+
call assert_fails("call term_start(&shell, {'cwd': 'Xdir'})", 'E475:')
491+
492+
" Case 3: Directory exists but is not accessible.
493+
call mkdir('Xdir', '', '0600')
494+
" return early if the directory permissions could not be set properly
495+
if getfperm('Xdir')[2] == 'x'
496+
call delete('Xdir', 'rf')
497+
return
498+
endif
499+
call assert_fails("call term_start(&shell, {'cwd': 'Xdir'})", 'E475:')
500+
call delete('Xdir', 'rf')
501+
endfunc
502+
481503
func Test_terminal_servername()
482504
if !has('clientserver')
483505
return

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,8 @@ static char *(features[]) =
792792

793793
static int included_patches[] =
794794
{ /* Add new patch number below this line */
795+
/**/
796+
485,
795797
/**/
796798
484,
797799
/**/

0 commit comments

Comments
 (0)