summaryrefslogtreecommitdiffstats
path: root/Modules/_winapi.c
diff options
context:
space:
mode:
authorVladimir Matveev <v2matveev@outlook.com>2018-12-14 08:30:51 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2018-12-14 08:30:51 (GMT)
commit7b36016a15aeed0d76a4c05a66203e6d7723aace (patch)
tree73f19994cdacbbfa4f4ec21c2f3ef1b8418c51ad /Modules/_winapi.c
parent08c2ba0717089662132af69bf5948d82277a8a69 (diff)
downloadcpython-7b36016a15aeed0d76a4c05a66203e6d7723aace.zip
cpython-7b36016a15aeed0d76a4c05a66203e6d7723aace.tar.gz
cpython-7b36016a15aeed0d76a4c05a66203e6d7723aace.tar.bz2
bpo-31446: Copy command line that should be passed to CreateProcessW(). (GH-11141)
Diffstat (limited to 'Modules/_winapi.c')
-rw-r--r--Modules/_winapi.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/Modules/_winapi.c b/Modules/_winapi.c
index 44788e5..852e0a7 100644
--- a/Modules/_winapi.c
+++ b/Modules/_winapi.c
@@ -975,7 +975,8 @@ cleanup:
_winapi.CreateProcess
application_name: Py_UNICODE(accept={str, NoneType})
- command_line: Py_UNICODE(accept={str, NoneType})
+ command_line: object
+ Can be str or None
proc_attrs: object
Ignored internally, can be None.
thread_attrs: object
@@ -995,12 +996,12 @@ process ID, and thread ID.
static PyObject *
_winapi_CreateProcess_impl(PyObject *module, Py_UNICODE *application_name,
- Py_UNICODE *command_line, PyObject *proc_attrs,
+ PyObject *command_line, PyObject *proc_attrs,
PyObject *thread_attrs, BOOL inherit_handles,
DWORD creation_flags, PyObject *env_mapping,
Py_UNICODE *current_directory,
PyObject *startup_info)
-/*[clinic end generated code: output=4652a33aff4b0ae1 input=4a43b05038d639bb]*/
+/*[clinic end generated code: output=2ecaab46a05e3123 input=42ac293eaea03fc4]*/
{
PyObject *ret = NULL;
BOOL result;
@@ -1008,6 +1009,7 @@ _winapi_CreateProcess_impl(PyObject *module, Py_UNICODE *application_name,
STARTUPINFOEXW si;
PyObject *environment = NULL;
wchar_t *wenvironment;
+ wchar_t *command_line_copy = NULL;
AttributeList attribute_list = {0};
ZeroMemory(&si, sizeof(si));
@@ -1042,10 +1044,23 @@ _winapi_CreateProcess_impl(PyObject *module, Py_UNICODE *application_name,
goto cleanup;
si.lpAttributeList = attribute_list.attribute_list;
+ if (PyUnicode_Check(command_line)) {
+ command_line_copy = PyUnicode_AsWideCharString(command_line, NULL);
+ if (command_line_copy == NULL) {
+ goto cleanup;
+ }
+ }
+ else if (command_line != Py_None) {
+ PyErr_Format(PyExc_TypeError,
+ "CreateProcess() argument 2 must be str or None, not %s",
+ Py_TYPE(command_line)->tp_name);
+ goto cleanup;
+ }
+
Py_BEGIN_ALLOW_THREADS
result = CreateProcessW(application_name,
- command_line,
+ command_line_copy,
NULL,
NULL,
inherit_handles,
@@ -1069,6 +1084,7 @@ _winapi_CreateProcess_impl(PyObject *module, Py_UNICODE *application_name,
pi.dwThreadId);
cleanup:
+ PyMem_Free(command_line_copy);
Py_XDECREF(environment);
freeattributelist(&attribute_list);