aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRui Abreu Ferreira <raf-ep@gmx.com>2017-03-28 16:03:53 +0100
committerJustin M. Keyes <justinkz@gmail.com>2017-04-12 02:10:34 +0200
commitf3cc843755a6d638ada77dc31721aa53b3ff2364 (patch)
treeec2a760337b8d700ae7398feea43230e5b762ca8 /src
parent799443c9942fa145320d9cc7c4638bdaa8c8d67a (diff)
downloadrneovim-f3cc843755a6d638ada77dc31721aa53b3ff2364.tar.gz
rneovim-f3cc843755a6d638ada77dc31721aa53b3ff2364.tar.bz2
rneovim-f3cc843755a6d638ada77dc31721aa53b3ff2364.zip
win: libuv_process_spawn(): special-case cmd.exe
Disable CommandLineToArgvW-standard quoting for cmd.exe. libuv assumes spawned processes follow the convention expected by CommandLineToArgvW(). But cmd.exe is non-conformant, so for cmd.exe: - With system([]), the caller has full control (and responsibility) to quote arguments correctly. - With system(''), shell* options are used. libuv quoting is disabled if argv[0] is: - cmd.exe - cmd - $COMSPEC resolving to a path with filename cmd.exe Closes #6329 References #6387
Diffstat (limited to 'src')
-rw-r--r--src/nvim/event/libuv_process.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/nvim/event/libuv_process.c b/src/nvim/event/libuv_process.c
index 3da0c386b4..ab69bea04c 100644
--- a/src/nvim/event/libuv_process.c
+++ b/src/nvim/event/libuv_process.c
@@ -8,6 +8,8 @@
#include "nvim/event/process.h"
#include "nvim/event/libuv_process.h"
#include "nvim/log.h"
+#include "nvim/path.h"
+#include "nvim/os/os.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/libuv_process.c.generated.h"
@@ -24,6 +26,26 @@ int libuv_process_spawn(LibuvProcess *uvproc)
if (proc->detach) {
uvproc->uvopts.flags |= UV_PROCESS_DETACHED;
}
+#ifdef WIN32
+ // libuv assumes spawned processes follow the convention from
+ // CommandLineToArgvW(), cmd.exe does not. Disable quoting since it will
+ // result in unexpected behaviour, the caller is left with the responsibility
+ // to quote arguments accordingly. system('') has shell* options for this.
+ //
+ // Disable quoting for cmd, cmd.exe and $COMSPEC with a cmd.exe filename
+ bool is_cmd = STRICMP(proc->argv[0], "cmd.exe") == 0
+ || STRICMP(proc->argv[0], "cmd") == 0;
+ if (!is_cmd) {
+ const char_u *comspec = (char_u *)os_getenv("COMSPEC");
+ const char_u *comspecshell = path_tail((char_u *)proc->argv[0]);
+ is_cmd = comspec != NULL && STRICMP(proc->argv[0], comspec) == 0
+ && STRICMP("cmd.exe", (char *)comspecshell) == 0;
+ }
+
+ if (is_cmd) {
+ uvproc->uvopts.flags |= UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS;
+ }
+#endif
uvproc->uvopts.exit_cb = exit_cb;
uvproc->uvopts.cwd = proc->cwd;
uvproc->uvopts.env = NULL;