Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix is_terminal's handling of long paths on Windows. #108391

Merged

Conversation

sunfishcode
Copy link
Member

@sunfishcode sunfishcode commented Feb 23, 2023

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.

@rustbot
Copy link
Collaborator

rustbot commented Feb 23, 2023

r? @ChrisDenton

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 23, 2023
@rustbot
Copy link
Collaborator

rustbot commented Feb 23, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@ChrisDenton ChrisDenton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. I only have a very minor doc comment nit. Also if you could squish the commits into one then I'll ask bors to merge.

library/std/src/sys/windows/io.rs Outdated Show resolved Hide resolved
@sunfishcode sunfishcode force-pushed the sunfishcode/is-terminal-file-length branch from a7a395a to 46eddd4 Compare February 23, 2023 14:27
@sunfishcode
Copy link
Member Author

I've now sqashed the commits into one.

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.
@sunfishcode sunfishcode force-pushed the sunfishcode/is-terminal-file-length branch from 46eddd4 to c0c1925 Compare February 23, 2023 14:29
@ChrisDenton
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 23, 2023

📌 Commit c0c1925 has been approved by ChrisDenton

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 23, 2023
bors added a commit to rust-lang/cargo that referenced this pull request Feb 23, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 23, 2023
…l-file-length, r=ChrisDenton

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.
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 24, 2023
Rollup of 10 pull requests

Successful merges:

 - rust-lang#106541 (implement const iterator using `rustc_do_not_const_check`)
 - rust-lang#106918 (Rebuild BinaryHeap on unwind from retain)
 - rust-lang#106923 (Restore behavior when primary bundle is missing)
 - rust-lang#108169 (Make query keys `Copy`)
 - rust-lang#108287 (Add test for bad cast with deferred projection equality)
 - rust-lang#108370 (std: time: Avoid to use "was created" in elapsed() description)
 - rust-lang#108377 (Fix ICE in 'duplicate diagnostic item' diagnostic)
 - rust-lang#108388 (parser: provide better suggestions and errors on closures with braces missing)
 - rust-lang#108391 (Fix `is_terminal`'s handling of long paths on Windows.)
 - rust-lang#108401 (diagnostics: remove inconsistent English article "this" from E0107)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 353827a into rust-lang:master Feb 24, 2023
@rustbot rustbot added this to the 1.69.0 milestone Feb 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants