aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTommy Allen <tommy@esdf.io>2018-11-07 04:31:25 -0500
committerJustin M. Keyes <justinkz@gmail.com>2018-11-07 10:31:25 +0100
commitc4c74c3883aa3122c0c877ca8dd7b26beb5cc4aa (patch)
tree41eab89a4dda67634836178f4b374ab35630bb92
parent769d164c70bee1877d101447ba41730147a2f127 (diff)
downloadrneovim-c4c74c3883aa3122c0c877ca8dd7b26beb5cc4aa.tar.gz
rneovim-c4c74c3883aa3122c0c877ca8dd7b26beb5cc4aa.tar.bz2
rneovim-c4c74c3883aa3122c0c877ca8dd7b26beb5cc4aa.zip
jobstart(): Fix hang on non-executable cwd #9204
* os/fs.c: add os_isdir_executable() * eval.c: fix hang on job start caused by non-executable cwd option * channel.c: assert cwd is an executable directory * test: jobstart() produces error when using non-executable cwd
-rw-r--r--src/nvim/channel.c2
-rw-r--r--src/nvim/eval.c4
-rw-r--r--src/nvim/os/fs.c21
-rw-r--r--test/functional/core/job_spec.lua12
4 files changed, 36 insertions, 3 deletions
diff --git a/src/nvim/channel.c b/src/nvim/channel.c
index 259f1cc600..58a34acb22 100644
--- a/src/nvim/channel.c
+++ b/src/nvim/channel.c
@@ -284,6 +284,8 @@ Channel *channel_job_start(char **argv, CallbackReader on_stdout,
uint16_t pty_width, uint16_t pty_height,
char *term_name, varnumber_T *status_out)
{
+ assert(cwd == NULL || os_isdir_executable(cwd));
+
Channel *chan = channel_alloc(kChannelStreamProc);
chan->on_stdout = on_stdout;
chan->on_stderr = on_stderr;
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 2fb9bd7367..9c7af0a87d 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -11724,7 +11724,7 @@ static void f_jobstart(typval_T *argvars, typval_T *rettv, FunPtr fptr)
if (new_cwd && strlen(new_cwd) > 0) {
cwd = new_cwd;
// The new cwd must be a directory.
- if (!os_isdir((char_u *)cwd)) {
+ if (!os_isdir_executable((const char *)cwd)) {
EMSG2(_(e_invarg2), "expected valid directory");
shell_free_argv(argv);
return;
@@ -16769,7 +16769,7 @@ static void f_termopen(typval_T *argvars, typval_T *rettv, FunPtr fptr)
if (new_cwd && *new_cwd != NUL) {
cwd = new_cwd;
// The new cwd must be a directory.
- if (!os_isdir((const char_u *)cwd)) {
+ if (!os_isdir_executable((const char *)cwd)) {
EMSG2(_(e_invarg2), "expected valid directory");
shell_free_argv(argv);
return;
diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c
index cf00fd4f82..9a4391a0ae 100644
--- a/src/nvim/os/fs.c
+++ b/src/nvim/os/fs.c
@@ -110,7 +110,7 @@ bool os_isrealdir(const char *name)
/// Check if the given path is a directory or not.
///
-/// @return `true` if `fname` is a directory.
+/// @return `true` if `name` is a directory.
bool os_isdir(const char_u *name)
FUNC_ATTR_NONNULL_ALL
{
@@ -126,6 +126,25 @@ bool os_isdir(const char_u *name)
return true;
}
+/// Check if the given path is a directory and is executable.
+/// Gives the same results as `os_isdir()` on Windows.
+///
+/// @return `true` if `name` is a directory and executable.
+bool os_isdir_executable(const char *name)
+ FUNC_ATTR_NONNULL_ALL
+{
+ int32_t mode = os_getperm((const char *)name);
+ if (mode < 0) {
+ return false;
+ }
+
+#ifdef WIN32
+ return (S_ISDIR(mode));
+#else
+ return (S_ISDIR(mode) && (S_IXUSR & mode));
+#endif
+}
+
/// Check what `name` is:
/// @return NODE_NORMAL: file or directory (or doesn't exist)
/// NODE_WRITABLE: writable device, socket, fifo, etc.
diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua
index 34168e10c2..eb02610df0 100644
--- a/test/functional/core/job_spec.lua
+++ b/test/functional/core/job_spec.lua
@@ -17,6 +17,7 @@ local pathroot = helpers.pathroot
local nvim_set = helpers.nvim_set
local expect_twostreams = helpers.expect_twostreams
local expect_msg_seq = helpers.expect_msg_seq
+local expect_err = helpers.expect_err
local Screen = require('test.functional.ui.screen')
-- Kill process with given pid
@@ -115,6 +116,17 @@ describe('jobs', function()
ok(string.find(err, "E475: Invalid argument: expected valid directory$") ~= nil)
end)
+ it('produces error when using non-executable `cwd`', function()
+ if iswin() then return end -- N/A for Windows
+
+ local dir = 'Xtest_not_executable_dir'
+ mkdir(dir)
+ funcs.setfperm(dir, 'rw-------')
+ expect_err('E475: Invalid argument: expected valid directory$', nvim,
+ 'command', "call jobstart('pwd', {'cwd': '" .. dir .. "'})")
+ rmdir(dir)
+ end)
+
it('returns 0 when it fails to start', function()
eq("", eval("v:errmsg"))
feed_command("let g:test_jobid = jobstart([])")