summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorJames Ross-Gowan <rossymiles@gmail.com>2015-01-16 22:21:02 +1100
committerDiogo Franco (Kovensky) <diogomfranco@gmail.com>2015-01-25 17:00:10 +0900
commit804468b1ac0fcbf40e3759ed1e6e9921e26ad5a7 (patch)
treecabe88adb28b764bd6f79c2f5b8735f6689a87e5 /osdep
parentd8455f34c13a002a01c9b3a9e356a98edfececeb (diff)
downloadmpv-804468b1ac0fcbf40e3759ed1e6e9921e26ad5a7.tar.bz2
mpv-804468b1ac0fcbf40e3759ed1e6e9921e26ad5a7.tar.xz
subprocess-win: Always quote argv[0]
If the program name isn't quoted and the .exe it refers to isn't found, CreateProcess will add the program arguments to the program name and continue searching, so for "program arg1 arg2", CreateProcess would try "program.exe", "program arg1.exe", then "program arg1 arg2.exe". This behaviour is weird and not really desirable, so prevent it by always quoting the program name. When quoting argv[0], escape sequences shouldn't be used. msvcrt, .NET and CommandLineToArgvW all treat argv[0] literally and end it on the trailing quote, without processing escape sequences.
Diffstat (limited to 'osdep')
-rw-r--r--osdep/subprocess-win.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/osdep/subprocess-win.c b/osdep/subprocess-win.c
index bdc78c939d..c793b67546 100644
--- a/osdep/subprocess-win.c
+++ b/osdep/subprocess-win.c
@@ -84,12 +84,14 @@ static void write_arg(bstr *cmdline, char *arg)
// Convert an array of arguments to a properly escaped command-line string
static wchar_t *write_cmdline(void *ctx, char **argv)
{
+ // argv[0] should always be quoted. Otherwise, arguments may be interpreted
+ // as part of the program name. Also, it can't contain escape sequences.
bstr cmdline = {0};
+ bstr_xappend_asprintf(NULL, &cmdline, "\"%s\"", argv[0]);
- for (int i = 0; argv[i]; i++) {
+ for (int i = 1; argv[i]; i++) {
+ bstr_xappend(NULL, &cmdline, bstr0(" "));
write_arg(&cmdline, argv[i]);
- if (argv[i + 1])
- bstr_xappend(NULL, &cmdline, bstr0(" "));
}
wchar_t *wcmdline = mp_from_utf8(ctx, cmdline.start);