andfoy / winpty-rs

Create and spawn processes inside a pseudoterminal in Windows from Rust
Other
23 stars 7 forks source link

Build fails because PCWSTR content expires and overwritten before it is used #57

Closed IcedLance closed 1 year ago

IcedLance commented 1 year ago

In build.rs the function fn into_pcwstr(self) -> PCWSTR returns PCWSTR which is basically a pointer to an internal variable that expires immediately after function returns, and even though it's used immediately it's apparently enough for the data it points to get corrupted.

I believe windows-rs library it relies on has already addressed this issue and provided some workaround in release 0.44.0. Right now winpty-rs is using windows 0.43.0

This is the description of the change microsoft/windows-rs#2239 and apparently you can use HSTRING instead of PCWSTR in most cases now, which is safer. This seems to work:

GetModuleHandleW(&HSTRING::from("kernel32.dll"))
andfoy commented 1 year ago

Thanks for raising this up @IcedLance, I'll produce a new release once I update the windows-rs requirement