Skip to content

gh-159237: Fix buffer type confusion in _winapi.CreateProcess audit event - #159238

Merged
vstinner merged 3 commits into
python:mainfrom
aisk:fix-winapi-createprocess-audit
Dec 4, 2026
Merged

vstinner merged 3 commits into
python:mainfrom
aisk:fix-winapi-createprocess-audit

Conversation

@aisk

@aisk aisk commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to wait until the child process completes. Can you apply this patch?

diff --git a/Lib/test/audit-tests.py b/Lib/test/audit-tests.py
index 275555cefbb..235b7330ff9 100644
--- a/Lib/test/audit-tests.py
+++ b/Lib/test/audit-tests.py
@@ -9,6 +9,7 @@
 import os
 import sys
 import unittest.mock
+from test import support
 from test.support import swap_item
 
 
@@ -668,11 +669,18 @@ def hook(event, args):
             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)
+
+    timeout = support.SHORT_TIMEOUT
+    timeout = int(timeout * 1000)
+    result = _winapi.WaitForSingleObject(hp, timeout)
     _winapi.CloseHandle(hp)
+    if result == _winapi.WAIT_TIMEOUT:
+        raise TimeoutError(f"process still running after {timeout} ms")
 
 
 def test_assert_unicode():

Co-authored-by: Victor Stinner <vstinner@python.org>
@aisk

aisk commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

@vstinner Applied!

@vstinner
vstinner merged commit 58e7eca into python:main Dec 4, 2026
57 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @aisk for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington-app

Copy link
Copy Markdown

Sorry, @aisk and @vstinner, I could not cleanly backport this to 3.14 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 58e7eca17a58596559ba3bfc8468c664e51b0c8e 3.14

@bedevere-app

bedevere-app Bot commented Dec 4, 2026

Copy link
Copy Markdown

GH-163158 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Dec 4, 2026
vstinner added a commit that referenced this pull request Dec 4, 2026
…` audit event (#163159)

gh-159237: Fix buffer type confusion in `_winapi.CreateProcess` audit event (#159238)


(cherry picked from commit 58e7eca)

Co-authored-by: An Long <aisk@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs backport to 3.14 bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants