Skip to content
Open
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
16 changes: 16 additions & 0 deletions Lib/test/audit-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,22 @@ def hook(event, args):
_winapi.CreateNamedPipe(pipe_name, _winapi.PIPE_ACCESS_DUPLEX, 8, 2, 0, 0, 0, 0)


def test_winapi_createprocess(command_line):
import _winapi
import subprocess

def hook(event, args):
if event == "_winapi.CreateProcess":
print(event, args)

sys.addaudithook(hook)
hp, ht, _, _ = _winapi.CreateProcess(
sys.executable, command_line, None, None, False, 0, None, None,
subprocess.STARTUPINFO())
_winapi.CloseHandle(ht)
_winapi.CloseHandle(hp)


def test_assert_unicode():
import sys
sys.addaudithook(lambda *args: None)
Expand Down
16 changes: 16 additions & 0 deletions Lib/test/test_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,22 @@ def test_winapi_createnamedpipe(self):

self.assertEqual(actual, expected)

def test_winapi_createprocess(self):
winapi = import_helper.import_module("_winapi")

command_line = "python -c pass"
returncode, events, stderr = self.run_python("test_winapi_createprocess", command_line)
if returncode:
self.fail(stderr)

if support.verbose:
print(*events, sep='\n')
actual = [(ev[0], ev[2]) for ev in events]
expected = [("_winapi.CreateProcess",
f"({sys.executable!r}, {command_line!r}, None)")]

self.assertEqual(actual, expected)

def test_assert_unicode(self):
# See gh-126018
returncode, _, stderr = self.run_python("test_assert_unicode")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix the ``_winapi.CreateProcess`` audit event passing garbage instead of the
*command_line* argument to audit hooks.
2 changes: 1 addition & 1 deletion Modules/_winapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ _winapi_CreateProcess_impl(PyObject *module, const wchar_t *application_name,
wchar_t *command_line_copy = NULL;
AttributeList attribute_list = {0};

if (PySys_Audit("_winapi.CreateProcess", "uuu", application_name,
if (PySys_Audit("_winapi.CreateProcess", "uOu", application_name,
command_line, current_directory) < 0) {
return NULL;
}
Expand Down
Loading