Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Copy command line that was passed to CreateProcessW since this function can
change the content of the input buffer.
24 changes: 20 additions & 4 deletions Modules/_winapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,8 @@ getattributelist(PyObject *obj, const char *name, AttributeList *attribute_list)
_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
Expand All @@ -995,19 +996,20 @@ 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;
PROCESS_INFORMATION pi;
STARTUPINFOEXW si;
PyObject *environment = NULL;
wchar_t *wenvironment;
wchar_t *command_line_copy = NULL;
AttributeList attribute_list = {0};

ZeroMemory(&si, sizeof(si));
Expand Down Expand Up @@ -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,
Expand All @@ -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);

Expand Down
10 changes: 6 additions & 4 deletions Modules/clinic/_winapi.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.