Repository navigation
Description
Bug report
Description
A C-level argument type mismatch exists in the implementation of the _winapi.CreateProcess audit event on Windows.
In CPython 3.13.17, Modules/_winapi.c declares the relevant arguments as:
const wchar_t *application_name;
PyObject *command_line;
const wchar_t *current_directory;However, the audit event is constructed using:
if (PySys_Audit("_winapi.CreateProcess", "uuu",
application_name,
command_line,
current_directory) < 0) {
return NULL;
}The middle argument is a PyObject *, whereas the format specifier u expects a wide-character string pointer.
Source-level analysis
In Python/modsupport.c, the implementation of the u format specifier retrieves a wchar_t * argument and uses wcslen when no explicit length is supplied.
Consequently, the audit argument construction may interpret Python object memory as wide-character string data instead of accessing the actual Unicode string contents.
The conversion of command_line using PyUnicode_AsWideCharString occurs later in _winapi.CreateProcess.
Furthermore, Python/sysmodule.c constructs the audit argument tuple using Py_VaBuildValue before dispatching the event to registered audit hooks.
Therefore, ignoring the malformed argument inside an audit hook does not prevent the preceding type-mismatched conversion.
Observed behavior
During an existing Windows subprocess qualification procedure, an audit hook rejected the _winapi.CreateProcess event because its command-line argument did not match the expected command line.
Subsequent static source analysis identified the type mismatch described above.
The original procedure was stopped. No additional runtime reproducer or crash test has been executed.
Expected behavior
The _winapi.CreateProcess audit event should provide the actual command-line argument with its correct value and type, without interpreting Python object memory as wide-character string data.
Proposed correction
Would changing the format string from "uuu" to "uOu" be appropriate?
- PySys_Audit("_winapi.CreateProcess", "uuu",
+ PySys_Audit("_winapi.CreateProcess", "uOu",The O format specifier accepts a PyObject *.
This is a proposed source-level correction only. It has not been implemented or tested.
The handling of None, invalid argument types, reference ownership and compatibility with the documented audit event should be considered when implementing the correction and regression tests.
Environment
- Windows 11 Professional, x64
- CPython 3.13.17, AMD64
- Audit hooks enabled
- Affected module:
_winapi
Source references
CPython tag: v3.13.17
Modules/_winapi.cPython/modsupport.cPython/sysmodule.c
Scope and limitations
The exact affected version range and installed binary-level behavior have not been fully established.
This report does not claim that every invocation crashes, that memory disclosure has been demonstrated, or that a specific exploitable security vulnerability has been established.
CPython versions tested on:
3.13
Operating systems tested on:
Windows
Activity
vstinner commentedon Dec 3, 2026
Yes, I think so. Do you want to propose a fix?
tonj4940-byte commentedon Dec 4, 2026
this is the fix: + PySys_Audit("_winapi.CreateProcess", "uOu",
vstinner commentedon Dec 4, 2026
Sorry, I mean: do you want to propose a pull request?
aisk commentedon Dec 4, 2026
Hi, thank you for reporting, but there is already an issue in #159237 with a fix.
_winapi.CreateProcessaudit event passes garbage forcommand_line#159237