]> granicus.if.org Git - vim/commitdiff
patch 8.1.0485: term_start() does not check if directory is accessible v8.1.0485
authorBram Moolenaar <Bram@vim.org>
Fri, 19 Oct 2018 14:53:39 +0000 (16:53 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 19 Oct 2018 14:53:39 +0000 (16:53 +0200)
Problem:    term_start() does not check if directory is accessible.
Solution:   Add mch_access() call. (Jason Franklin)

src/channel.c
src/testdir/test_terminal.vim
src/version.c

index aa0a0d38cae97bd753e203843613be9fdd5c9628..02ed3a8fc7151663134eae45e67029f3c748de30 100644 (file)
@@ -4916,7 +4916,8 @@ get_job_options(typval_T *tv, jobopt_T *opt, int supported, int supported2)
                if (!(supported2 & JO2_CWD))
                    break;
                opt->jo_cwd = get_tv_string_buf_chk(item, opt->jo_cwd_buf);
-               if (opt->jo_cwd == NULL || !mch_isdir(opt->jo_cwd))
+               if (opt->jo_cwd == NULL || !mch_isdir(opt->jo_cwd)
+                               || mch_access((char *)opt->jo_cwd, X_OK) != 0)
                {
                    EMSG2(_(e_invargval), "cwd");
                    return FAIL;
index b82dae13e3b274c2bb482da41e94efe3e929f889..235cd3160c95ab70d8090f4c5ec7205615ce8d20 100644 (file)
@@ -478,6 +478,28 @@ func Test_terminal_cwd()
   call delete('Xdir', 'rf')
 endfunc
 
+func Test_terminal_cwd_failure()
+  " Case 1: Provided directory is not actually a directory.  Attempt to make
+  " the file executable as well.
+  call writefile([], 'Xfile')
+  call setfperm('Xfile', 'rwx------')
+  call assert_fails("call term_start(&shell, {'cwd': 'Xfile'})", 'E475:')
+  call delete('Xfile')
+
+  " Case 2: Directory does not exist.
+  call assert_fails("call term_start(&shell, {'cwd': 'Xdir'})", 'E475:')
+
+  " Case 3: Directory exists but is not accessible.
+  call mkdir('Xdir', '', '0600')
+  " return early if the directory permissions could not be set properly
+  if getfperm('Xdir')[2] == 'x'
+    call delete('Xdir', 'rf')
+    return
+  endif
+  call assert_fails("call term_start(&shell, {'cwd': 'Xdir'})", 'E475:')
+  call delete('Xdir', 'rf')
+endfunc
+
 func Test_terminal_servername()
   if !has('clientserver')
     return
index ab54bb3120323070cd70fad75c1f5862d5da1989..4ed8adc2653c2819eea4dd46d40ffd639801f328 100644 (file)
@@ -792,6 +792,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    485,
 /**/
     484,
 /**/