mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-18 14:17:03 +01:00
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. (cherry picked from commit cf2f6d8a3f0594c03c383b4989a3041e9c4536d7)
This commit is contained in:
parent
f20e9a4644
commit
7a98e45e74
@ -414,9 +414,11 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
|
|||||||
0, /* Returns pid. */
|
0, /* Returns pid. */
|
||||||
0 /* Returns tid. */
|
0 /* Returns tid. */
|
||||||
};
|
};
|
||||||
STARTUPINFO si;
|
STARTUPINFOW si;
|
||||||
int cr_flags;
|
int cr_flags;
|
||||||
char *cmdline;
|
char *cmdline;
|
||||||
|
wchar_t *wcmdline = NULL;
|
||||||
|
wchar_t *wpgmname = NULL;
|
||||||
HANDLE inpipe[2] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE};
|
HANDLE inpipe[2] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE};
|
||||||
HANDLE outpipe[2] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE};
|
HANDLE outpipe[2] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE};
|
||||||
HANDLE errpipe[2] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE};
|
HANDLE errpipe[2] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE};
|
||||||
@ -426,7 +428,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
|
|||||||
HANDLE nullhd[3] = {INVALID_HANDLE_VALUE,
|
HANDLE nullhd[3] = {INVALID_HANDLE_VALUE,
|
||||||
INVALID_HANDLE_VALUE,
|
INVALID_HANDLE_VALUE,
|
||||||
INVALID_HANDLE_VALUE};
|
INVALID_HANDLE_VALUE};
|
||||||
int i;
|
int i, rc;
|
||||||
es_syshd_t syshd;
|
es_syshd_t syshd;
|
||||||
gpg_err_source_t errsource = default_errsource;
|
gpg_err_source_t errsource = default_errsource;
|
||||||
int nonblock = !!(flags & GNUPG_SPAWN_NONBLOCK);
|
int nonblock = !!(flags & GNUPG_SPAWN_NONBLOCK);
|
||||||
@ -564,9 +566,16 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
|
|||||||
| ((flags & GNUPG_SPAWN_DETACHED)? DETACHED_PROCESS : 0)
|
| ((flags & GNUPG_SPAWN_DETACHED)? DETACHED_PROCESS : 0)
|
||||||
| GetPriorityClass (GetCurrentProcess ())
|
| GetPriorityClass (GetCurrentProcess ())
|
||||||
| CREATE_SUSPENDED);
|
| CREATE_SUSPENDED);
|
||||||
/* log_debug ("CreateProcess, path='%s' cmdline='%s'\n", pgmname, cmdline); */
|
/* log_debug ("CreateProcess, path='%s' cmdline='%s'\n", */
|
||||||
if (!CreateProcess (pgmname, /* Program to start. */
|
/* pgmname, cmdline); */
|
||||||
cmdline, /* Command line arguments. */
|
/* Take care: CreateProcessW may modify wpgmname */
|
||||||
|
if (!(wpgmname = utf8_to_wchar (pgmname)))
|
||||||
|
rc = 0;
|
||||||
|
else if (!(wcmdline = utf8_to_wchar (cmdline)))
|
||||||
|
rc = 0;
|
||||||
|
else
|
||||||
|
rc = CreateProcessW (wpgmname, /* Program to start. */
|
||||||
|
wcmdline, /* Command line arguments. */
|
||||||
&sec_attr, /* Process security attributes. */
|
&sec_attr, /* Process security attributes. */
|
||||||
&sec_attr, /* Thread security attributes. */
|
&sec_attr, /* Thread security attributes. */
|
||||||
TRUE, /* Inherit handles. */
|
TRUE, /* Inherit handles. */
|
||||||
@ -575,9 +584,16 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
|
|||||||
NULL, /* Use current drive/directory. */
|
NULL, /* Use current drive/directory. */
|
||||||
&si, /* Startup information. */
|
&si, /* Startup information. */
|
||||||
&pi /* Returns process information. */
|
&pi /* Returns process information. */
|
||||||
))
|
);
|
||||||
|
if (!rc)
|
||||||
{
|
{
|
||||||
|
if (!wpgmname || !wcmdline)
|
||||||
|
log_error ("CreateProcess failed (utf8_to_wchar): %s\n",
|
||||||
|
strerror (errno));
|
||||||
|
else
|
||||||
log_error ("CreateProcess failed: %s\n", w32_strerror (-1));
|
log_error ("CreateProcess failed: %s\n", w32_strerror (-1));
|
||||||
|
xfree (wpgmname);
|
||||||
|
xfree (wcmdline);
|
||||||
xfree (cmdline);
|
xfree (cmdline);
|
||||||
if (infp)
|
if (infp)
|
||||||
es_fclose (infp);
|
es_fclose (infp);
|
||||||
@ -599,6 +615,8 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
|
|||||||
CloseHandle (errpipe[1]);
|
CloseHandle (errpipe[1]);
|
||||||
return gpg_err_make (errsource, GPG_ERR_GENERAL);
|
return gpg_err_make (errsource, GPG_ERR_GENERAL);
|
||||||
}
|
}
|
||||||
|
xfree (wpgmname);
|
||||||
|
xfree (wcmdline);
|
||||||
xfree (cmdline);
|
xfree (cmdline);
|
||||||
cmdline = NULL;
|
cmdline = NULL;
|
||||||
|
|
||||||
@ -660,9 +678,11 @@ gnupg_spawn_process_fd (const char *pgmname, const char *argv[],
|
|||||||
gpg_error_t err;
|
gpg_error_t err;
|
||||||
SECURITY_ATTRIBUTES sec_attr;
|
SECURITY_ATTRIBUTES sec_attr;
|
||||||
PROCESS_INFORMATION pi = { NULL, 0, 0, 0 };
|
PROCESS_INFORMATION pi = { NULL, 0, 0, 0 };
|
||||||
STARTUPINFO si;
|
STARTUPINFOW si;
|
||||||
char *cmdline;
|
char *cmdline;
|
||||||
int i;
|
wchar_t *wcmdline = NULL;
|
||||||
|
wchar_t *wpgmname = NULL;
|
||||||
|
int i, rc;
|
||||||
HANDLE stdhd[3];
|
HANDLE stdhd[3];
|
||||||
|
|
||||||
/* Setup return values. */
|
/* Setup return values. */
|
||||||
@ -690,8 +710,14 @@ gnupg_spawn_process_fd (const char *pgmname, const char *argv[],
|
|||||||
si.hStdError = errfd == -1? stdhd[2] : (void*)_get_osfhandle (errfd);
|
si.hStdError = errfd == -1? stdhd[2] : (void*)_get_osfhandle (errfd);
|
||||||
|
|
||||||
/* log_debug ("CreateProcess, path='%s' cmdline='%s'\n", pgmname, cmdline); */
|
/* log_debug ("CreateProcess, path='%s' cmdline='%s'\n", pgmname, cmdline); */
|
||||||
if (!CreateProcess (pgmname, /* Program to start. */
|
/* Take care: CreateProcessW may modify wpgmname */
|
||||||
cmdline, /* Command line arguments. */
|
if (!(wpgmname = utf8_to_wchar (pgmname)))
|
||||||
|
rc = 0;
|
||||||
|
else if (!(wcmdline = utf8_to_wchar (cmdline)))
|
||||||
|
rc = 0;
|
||||||
|
else
|
||||||
|
rc = CreateProcessW (wpgmname, /* Program to start. */
|
||||||
|
wcmdline, /* Command line arguments. */
|
||||||
&sec_attr, /* Process security attributes. */
|
&sec_attr, /* Process security attributes. */
|
||||||
&sec_attr, /* Thread security attributes. */
|
&sec_attr, /* Thread security attributes. */
|
||||||
TRUE, /* Inherit handles. */
|
TRUE, /* Inherit handles. */
|
||||||
@ -702,13 +728,20 @@ gnupg_spawn_process_fd (const char *pgmname, const char *argv[],
|
|||||||
NULL, /* Use current drive/directory. */
|
NULL, /* Use current drive/directory. */
|
||||||
&si, /* Startup information. */
|
&si, /* Startup information. */
|
||||||
&pi /* Returns process information. */
|
&pi /* Returns process information. */
|
||||||
))
|
);
|
||||||
|
if (!rc)
|
||||||
{
|
{
|
||||||
|
if (!wpgmname || !wcmdline)
|
||||||
|
log_error ("CreateProcess failed (utf8_to_wchar): %s\n",
|
||||||
|
strerror (errno));
|
||||||
|
else
|
||||||
log_error ("CreateProcess failed: %s\n", w32_strerror (-1));
|
log_error ("CreateProcess failed: %s\n", w32_strerror (-1));
|
||||||
err = my_error (GPG_ERR_GENERAL);
|
err = my_error (GPG_ERR_GENERAL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
err = 0;
|
err = 0;
|
||||||
|
xfree (wpgmname);
|
||||||
|
xfree (wcmdline);
|
||||||
xfree (cmdline);
|
xfree (cmdline);
|
||||||
for (i=0; i < 3; i++)
|
for (i=0; i < 3; i++)
|
||||||
if (stdhd[i] != INVALID_HANDLE_VALUE)
|
if (stdhd[i] != INVALID_HANDLE_VALUE)
|
||||||
@ -852,11 +885,14 @@ gnupg_spawn_process_detached (const char *pgmname, const char *argv[],
|
|||||||
0, /* Returns pid. */
|
0, /* Returns pid. */
|
||||||
0 /* Returns tid. */
|
0 /* Returns tid. */
|
||||||
};
|
};
|
||||||
STARTUPINFO si;
|
STARTUPINFOW si;
|
||||||
int cr_flags;
|
int cr_flags;
|
||||||
char *cmdline;
|
char *cmdline;
|
||||||
gpg_err_code_t ec;
|
wchar_t *wcmdline = NULL;
|
||||||
|
wchar_t *wpgmname = NULL;
|
||||||
BOOL in_job = FALSE;
|
BOOL in_job = FALSE;
|
||||||
|
gpg_err_code_t ec;
|
||||||
|
int rc;
|
||||||
|
|
||||||
/* We don't use ENVP. */
|
/* We don't use ENVP. */
|
||||||
(void)envp;
|
(void)envp;
|
||||||
@ -930,8 +966,14 @@ gnupg_spawn_process_detached (const char *pgmname, const char *argv[],
|
|||||||
|
|
||||||
/* log_debug ("CreateProcess(detached), path='%s' cmdline='%s'\n", */
|
/* log_debug ("CreateProcess(detached), path='%s' cmdline='%s'\n", */
|
||||||
/* pgmname, cmdline); */
|
/* pgmname, cmdline); */
|
||||||
if (!CreateProcess (pgmname, /* Program to start. */
|
/* Take care: CreateProcessW may modify wpgmname */
|
||||||
cmdline, /* Command line arguments. */
|
if (!(wpgmname = utf8_to_wchar (pgmname)))
|
||||||
|
rc = 0;
|
||||||
|
else if (!(wcmdline = utf8_to_wchar (cmdline)))
|
||||||
|
rc = 0;
|
||||||
|
else
|
||||||
|
rc = CreateProcessW (wpgmname, /* Program to start. */
|
||||||
|
wcmdline, /* Command line arguments. */
|
||||||
&sec_attr, /* Process security attributes. */
|
&sec_attr, /* Process security attributes. */
|
||||||
&sec_attr, /* Thread security attributes. */
|
&sec_attr, /* Thread security attributes. */
|
||||||
FALSE, /* Inherit handles. */
|
FALSE, /* Inherit handles. */
|
||||||
@ -940,12 +982,21 @@ gnupg_spawn_process_detached (const char *pgmname, const char *argv[],
|
|||||||
NULL, /* Use current drive/directory. */
|
NULL, /* Use current drive/directory. */
|
||||||
&si, /* Startup information. */
|
&si, /* Startup information. */
|
||||||
&pi /* Returns process information. */
|
&pi /* Returns process information. */
|
||||||
))
|
);
|
||||||
|
if (!rc)
|
||||||
{
|
{
|
||||||
|
if (!wpgmname || !wcmdline)
|
||||||
|
log_error ("CreateProcess failed (utf8_to_wchar): %s\n",
|
||||||
|
strerror (errno));
|
||||||
|
else
|
||||||
log_error ("CreateProcess(detached) failed: %s\n", w32_strerror (-1));
|
log_error ("CreateProcess(detached) failed: %s\n", w32_strerror (-1));
|
||||||
|
xfree (wpgmname);
|
||||||
|
xfree (wcmdline);
|
||||||
xfree (cmdline);
|
xfree (cmdline);
|
||||||
return my_error (GPG_ERR_GENERAL);
|
return my_error (GPG_ERR_GENERAL);
|
||||||
}
|
}
|
||||||
|
xfree (wpgmname);
|
||||||
|
xfree (wcmdline);
|
||||||
xfree (cmdline);
|
xfree (cmdline);
|
||||||
cmdline = NULL;
|
cmdline = NULL;
|
||||||
|
|
||||||
|
14
g10/exec.c
14
g10/exec.c
@ -142,28 +142,36 @@ w32_system(const char *command)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
char *string;
|
char *string;
|
||||||
|
wchar_t *wstring;
|
||||||
PROCESS_INFORMATION pi;
|
PROCESS_INFORMATION pi;
|
||||||
STARTUPINFO si;
|
STARTUPINFOW si;
|
||||||
|
|
||||||
/* We must use a copy of the command as CreateProcess modifies
|
/* We must use a copy of the command as CreateProcess modifies
|
||||||
* this argument. */
|
* this argument. */
|
||||||
string = xstrdup (command);
|
string = xstrdup (command);
|
||||||
|
wstring = utf8_to_wchar (string);
|
||||||
|
xfree (string);
|
||||||
|
if (!wstring)
|
||||||
|
return -1;
|
||||||
|
|
||||||
memset (&pi, 0, sizeof(pi));
|
memset (&pi, 0, sizeof(pi));
|
||||||
memset (&si, 0, sizeof(si));
|
memset (&si, 0, sizeof(si));
|
||||||
si.cb = sizeof (si);
|
si.cb = sizeof (si);
|
||||||
|
|
||||||
if (!CreateProcess (NULL, string, NULL, NULL, FALSE,
|
if (!CreateProcessW (NULL, wstring, NULL, NULL, FALSE,
|
||||||
DETACHED_PROCESS,
|
DETACHED_PROCESS,
|
||||||
NULL, NULL, &si, &pi))
|
NULL, NULL, &si, &pi))
|
||||||
|
{
|
||||||
|
xfree (wstring);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Wait for the child to exit */
|
/* Wait for the child to exit */
|
||||||
WaitForSingleObject (pi.hProcess, INFINITE);
|
WaitForSingleObject (pi.hProcess, INFINITE);
|
||||||
|
|
||||||
CloseHandle (pi.hProcess);
|
CloseHandle (pi.hProcess);
|
||||||
CloseHandle (pi.hThread);
|
CloseHandle (pi.hThread);
|
||||||
xfree (string);
|
xfree (wstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user