Skip to content

Try not to use verbatim paths in Command::current_dir #138869

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

Merged
merged 2 commits into from
Apr 9, 2025

Conversation

ChrisDenton
Copy link
Member

@ChrisDenton ChrisDenton commented Mar 23, 2025

If possible, we should try not to use verbatim paths in Command::current_dir. It might work but it might also break code in the subprocess that assume the current directory isn't verbatim (including Windows APIs). cc @ehuss

Side note: we now have a lot of ad-hoc fixes like this spread about the place. It'd be good to make a proper WindowsPath type that handles all this in one place. But that's a bigger job for another PR.

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

@Noratrieb Noratrieb 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 reasonable to me, but I'd like someone with more clues about Windows to take a look as well. I don't know who'd be a great fit, feel free to assign whoever you want

@ChrisDenton
Copy link
Member Author

I'd like someone with more clues about Windows to take a look as well

I'm honestly not sure, so choosing someone at random:
r? @tgross35
Want to take a stab at this? Feel free to pass.

@rustbot rustbot assigned tgross35 and unassigned Noratrieb Mar 24, 2025
Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

I am also not a Windows expert but it looks pretty reasonable to me. Sorry for the delay, just a few nits/questions.

Comment on lines +354 to +363
/// Test that the path is absolute, fully qualified and unchanged when processed by the Windows API.
///
/// For example:
///
/// - `C:\path\to\file` will return true.
/// - `C:\path\to\nul` returns false because the Windows API will convert it to \\.\NUL
/// - `C:\path\to\..\file` returns false because it will be resolved to `C:\path\file`.
///
/// This is a useful property because it means the path can be converted from and to and verbatim
/// path just by changing the prefix.
Copy link
Contributor

Choose a reason for hiding this comment

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

Verbatim paths can contain special names like COM while regular paths cannot right? That may be worth mentioning and adding a test for.

Copy link
Member Author

Choose a reason for hiding this comment

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

The COM1, CON, AUX, etc cases is the same as the NUL case mentioned and tested. It can occur in paths but may be changed to e.g. \\.\COM1 for non-verbatim paths. I didn't add a test for the COM1 case because it is actually allowed on recent versions of Windows. Only the relative path COM1 would be converted to \\.\COM1 but that's not absolute in any case.

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

LGTM, r=me with the last commit squashed

If possible, we should try not to use verbatim paths in Command::current_dir. It might work but it might also break code (including some Windows APIs) that assume the current directory isn't verbatim.
@ChrisDenton
Copy link
Member Author

@bors r=tgross35

@bors
Copy link
Collaborator

bors commented Apr 9, 2025

📌 Commit edfc747 has been approved by tgross35

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 Apr 9, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 9, 2025
…ss35

Try not to use verbatim paths in `Command::current_dir`

If possible, we should try not to use verbatim paths in `Command::current_dir`. It might work but it might also break code in the subprocess that assume the current directory isn't verbatim (including Windows APIs). cc `@ehuss`

Side note: we now have a lot of ad-hoc fixes like this spread about the place. It'd be good to make a proper `WindowsPath` type that handles all this in one place. But that's a bigger job for another PR.
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 9, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#137412 (Ensure `swap_nonoverlapping` is really always untyped)
 - rust-lang#138869 (Try not to use verbatim paths in `Command::current_dir`)
 - rust-lang#138993 (Make `cfg_match!` a semitransparent macro)
 - rust-lang#139099 (Promise `array::from_fn` is generated in order of increasing indices)
 - rust-lang#139364 (Make the compiler suggest actual paths instead of visible paths if the visible paths are through any doc hidden path.)
 - rust-lang#139468 (Don't call `Span::with_parent` on the good path in `has_stashed_diagnostic`)
 - rust-lang#139481 (Add job summary links to post-merge report)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 9, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#138869 (Try not to use verbatim paths in `Command::current_dir`)
 - rust-lang#138993 (Make `cfg_match!` a semitransparent macro)
 - rust-lang#139099 (Promise `array::from_fn` is generated in order of increasing indices)
 - rust-lang#139364 (Make the compiler suggest actual paths instead of visible paths if the visible paths are through any doc hidden path.)
 - rust-lang#139468 (Don't call `Span::with_parent` on the good path in `has_stashed_diagnostic`)
 - rust-lang#139481 (Add job summary links to post-merge report)
 - rust-lang#139573 (Miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 9, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#138869 (Try not to use verbatim paths in `Command::current_dir`)
 - rust-lang#138993 (Make `cfg_match!` a semitransparent macro)
 - rust-lang#139099 (Promise `array::from_fn` is generated in order of increasing indices)
 - rust-lang#139364 (Make the compiler suggest actual paths instead of visible paths if the visible paths are through any doc hidden path.)
 - rust-lang#139468 (Don't call `Span::with_parent` on the good path in `has_stashed_diagnostic`)
 - rust-lang#139481 (Add job summary links to post-merge report)
 - rust-lang#139573 (Miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 9e541c4 into rust-lang:master Apr 9, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone Apr 9, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 9, 2025
Rollup merge of rust-lang#138869 - ChrisDenton:command-curdir, r=tgross35

Try not to use verbatim paths in `Command::current_dir`

If possible, we should try not to use verbatim paths in `Command::current_dir`. It might work but it might also break code in the subprocess that assume the current directory isn't verbatim (including Windows APIs). cc ``@ehuss``

Side note: we now have a lot of ad-hoc fixes like this spread about the place. It'd be good to make a proper `WindowsPath` type that handles all this in one place. But that's a bigger job for another PR.
@ChrisDenton ChrisDenton deleted the command-curdir branch April 10, 2025 11:41
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Apr 19, 2025
…ss35

Try not to use verbatim paths in `Command::current_dir`

If possible, we should try not to use verbatim paths in `Command::current_dir`. It might work but it might also break code in the subprocess that assume the current directory isn't verbatim (including Windows APIs). cc ``@ehuss``

Side note: we now have a lot of ad-hoc fixes like this spread about the place. It'd be good to make a proper `WindowsPath` type that handles all this in one place. But that's a bigger job for another PR.
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-compiler Relevant to the compiler team, which will review and decide on the PR/issue. 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