Skip to content
Merged
Prev Previous commit
Next Next commit
Fix CreateProcess with empty environment on Windows
Empty env dict produced a single null terminator, but
CreateProcessW requires a double null for a valid empty
environment block.
  • Loading branch information
youknowone committed Mar 20, 2026
commit 24a17192a03b1f2b726a749e3cdb24724d86e4e0
1 change: 0 additions & 1 deletion Lib/test/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -1903,7 +1903,6 @@ def test_run_with_pathlike_path_and_arguments(self):
res = subprocess.run(args)
self.assertEqual(res.returncode, 57)

@unittest.skipIf(mswindows, "TODO: RUSTPYTHON; empty env block fails nondeterministically")
@unittest.skipUnless(mswindows, "Maybe test trigger a leak on Ubuntu")
def test_run_with_an_empty_env(self):
# gh-105436: fix subprocess.run(..., env={}) broken on Windows
Expand Down
5 changes: 5 additions & 0 deletions crates/vm/src/stdlib/_winapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,11 @@ mod _winapi {
for (_, entry) in entries {
out.push(entry);
}
// Each entry ends with \0, so one more \0 terminates the block.
// For empty env, we need \0\0 as a valid empty environment block.
if out.is_empty() {
out.push_str("\0");
}
out.push_str("\0");
Ok(out.into_vec())
}
Expand Down