diff --git a/tests/tools/test_find_shell.py b/tests/tools/test_find_shell.py index d9b56bf31c4c5..78889da95cf1b 100644 --- a/tests/tools/test_find_shell.py +++ b/tests/tools/test_find_shell.py @@ -162,6 +162,23 @@ def fake_run(argv, **kwargs): assert local_mod._bash_starts(r"C:\Git\bin\bash.exe") is True assert calls[0][0][-1] == "/usr/bin/true; /usr/bin/cat --version >/dev/null" + assert calls[0][1]["stdin"] is subprocess.DEVNULL + + def test_mandatory_aslr_probe_detaches_stdin(self, monkeypatch): + import tools.environments.local as local_mod + + monkeypatch.setattr(local_mod, "_mandatory_aslr_enabled_cache", None) + calls = [] + + def fake_run(argv, **kwargs): + calls.append((argv, kwargs)) + return subprocess.CompletedProcess(argv, 0, stdout="ON\n", stderr="") + + monkeypatch.setattr(local_mod.subprocess, "run", fake_run) + monkeypatch.setattr(local_mod.shutil, "which", lambda _name: "powershell.exe") + + assert local_mod._mandatory_aslr_enabled() is True + assert calls[0][1]["stdin"] is subprocess.DEVNULL def test_aslr_failure_surfaces_targeted_windows_command( self, tmp_path, monkeypatch diff --git a/tools/environments/local.py b/tools/environments/local.py index 8b4450c720104..be8ba3b78c297 100644 --- a/tools/environments/local.py +++ b/tools/environments/local.py @@ -740,6 +740,7 @@ def _mandatory_aslr_enabled() -> "bool | None": "-Command", "(Get-ProcessMitigation -System).Aslr.ForceRelocateImages.ToString()", ], + stdin=subprocess.DEVNULL, capture_output=True, text=True, timeout=10, @@ -806,6 +807,7 @@ def _bash_starts(bash: str) -> bool: try: result = subprocess.run( [bash, "--noprofile", "--norc", "-c", _BASH_EXTERNAL_PROGRAM_PROBE], + stdin=subprocess.DEVNULL, capture_output=True, text=True, timeout=15,