mirror of
https://github.com/neovim/neovim.git
synced 2025-09-30 23:18:33 +00:00
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
This commit is contained in:

committed by
Justin M. Keyes

parent
769d164c70
commit
c4c74c3883
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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.
|
||||
|
Reference in New Issue
Block a user