Prevent ConPTY DLL loading from the current directory (#39262)

## Why

The Windows PTY implementation probed `conpty.dll` by bare name. Windows could
resolve that lookup to a DLL in the process current directory and load it when
creating a pseudoconsole.

## What changed

Resolve the ConPTY entry points from `kernel32.dll` without probing
`conpty.dll`.

## Testing

Add a Windows regression test that places a compatible `conpty.dll` in the
current directory, creates a ConPTY, and verifies that the DLL was not loaded.

GitOrigin-RevId: be78974362a99dce0c18186cf3e7bbd86a8de73c
This commit is contained in:
iceweasel-oai authored and copyberry committed 2026-08-18 19:09:33 +00:00
1 parent 785ecd7452
commit 726ec7ecbf
3 files changed
+73 -12

No files matched your search

+2 -12
View File
@@ -85,20 +85,10 @@ shared_library!(Ntdll,
) -> NTSTATUS,
);
fn load_conpty() -> ConPtyFuncs {
let kernel = ConPtyFuncs::open(Path::new("kernel32.dll")).expect(
lazy_static! {
static ref CONPTY: ConPtyFuncs = ConPtyFuncs::open(Path::new("kernel32.dll")).expect(
"this system does not support conpty. Windows 10 October 2018 or newer is required",
);
if let Ok(sideloaded) = ConPtyFuncs::open(Path::new("conpty.dll")) {
sideloaded
} else {
kernel
}
}
lazy_static! {
static ref CONPTY: ConPtyFuncs = load_conpty();
}
pub fn conpty_supported() -> bool {