Fix is_terminal
's handling of long paths on Windows.
As reported in sunfishcode/is-terminal#18, there are situations where `GetFileInformationByHandleEx` can write a file name length that is longer than the provided buffer. To avoid deferencing memory past the end of the buffer, use a bounds-checked function to form a slice to the buffer and handle the out-of-bounds case. This ports the fix from sunfishcode/is-terminal#19 to std's `is_terminal` implementation.
This commit is contained in:
parent
07c993eba8
commit
c0c1925774
2 changed files with 21 additions and 19 deletions
|
@ -539,14 +539,6 @@ pub struct SYMBOLIC_LINK_REPARSE_BUFFER {
|
|||
pub PathBuffer: WCHAR,
|
||||
}
|
||||
|
||||
/// NB: Use carefully! In general using this as a reference is likely to get the
|
||||
/// provenance wrong for the `PathBuffer` field!
|
||||
#[repr(C)]
|
||||
pub struct FILE_NAME_INFO {
|
||||
pub FileNameLength: DWORD,
|
||||
pub FileName: [WCHAR; 1],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct MOUNT_POINT_REPARSE_BUFFER {
|
||||
pub SubstituteNameOffset: c_ushort,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue