Skip to content

Windows: Incorrect command_line argument type in _winapi.CreateProcess audit event #162935

Duplicate

Description

@tonj4940-byte

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.c
  • Python/modsupport.c
  • Python/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

  1. added
    type-bug
    on Dec 1, 2026
  2. added
    extension-modules
    on Dec 1, 2026
  3. vstinner commented on Dec 3, 2026

    @vstinner
    Member

    Would changing the format string from "uuu" to "uOu" be appropriate?

    Yes, I think so. Do you want to propose a fix?

  4. tonj4940-byte commented on Dec 4, 2026

    @tonj4940-byte
    Author

    this is the fix: + PySys_Audit("_winapi.CreateProcess", "uOu",

  5. vstinner commented on Dec 4, 2026

    @vstinner
    Member

    Sorry, I mean: do you want to propose a pull request?

  6. aisk commented on Dec 4, 2026

    @aisk
    Member

    Hi, thank you for reporting, but there is already an issue in #159237 with a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-windowsextension-modulestype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions