From cf2f6d8a3f0594c03c383b4989a3041e9c4536d7 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 8 Mar 2021 21:26:16 +0100 Subject: w32: Change spawn functions to use Unicode version of CreateProcess. * common/exechelp-w32.c (gnupg_spawn_process): Change to use CreateProcessW. (gnupg_spawn_process_fd): Ditto. (gnupg_spawn_process_detached): Ditto. * g10/exec.c (w32_system): Ditto. -- GnuPG-bug-id: 4398 We do not use this weirdo CREATE_UNICODE_ENVIRONMENT flag because it does not make any sense to have non-ASCII names in the environment. I can't imagine why this should be used at all and rationale for this API features is, well, sparse. --- g10/exec.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'g10/exec.c') diff --git a/g10/exec.c b/g10/exec.c index f63904b39..f612c850a 100644 --- a/g10/exec.c +++ b/g10/exec.c @@ -107,28 +107,36 @@ w32_system(const char *command) else { char *string; + wchar_t *wstring; PROCESS_INFORMATION pi; - STARTUPINFO si; + STARTUPINFOW si; /* We must use a copy of the command as CreateProcess modifies * this argument. */ string = xstrdup (command); + wstring = utf8_to_wchar (string); + xfree (string); + if (!wstring) + return -1; memset (&pi, 0, sizeof(pi)); memset (&si, 0, sizeof(si)); si.cb = sizeof (si); - if (!CreateProcess (NULL, string, NULL, NULL, FALSE, - DETACHED_PROCESS, - NULL, NULL, &si, &pi)) - return -1; + if (!CreateProcessW (NULL, wstring, NULL, NULL, FALSE, + DETACHED_PROCESS, + NULL, NULL, &si, &pi)) + { + xfree (wstring); + return -1; + } /* Wait for the child to exit */ WaitForSingleObject (pi.hProcess, INFINITE); CloseHandle (pi.hProcess); CloseHandle (pi.hThread); - xfree (string); + xfree (wstring); } return 0; -- cgit v1.2.3