mirror of
https://github.com/mpv-player/mpv.git
synced 2024-09-20 12:02:23 +02:00
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.
This commit is contained in:
parent
0092ae8676
commit
42fa954849
@ -83,12 +83,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);
|
||||
|
Loading…
Reference in New Issue
Block a user