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

Quote bat script command line #92208

Merged
merged 1 commit into from
Dec 23, 2021
Merged

Conversation

ChrisDenton
Copy link
Contributor

Fixes #91991

CreateProcessW should only be used to run exe files but it does have some (undocumented) special handling for files with .bat and .cmd extensions. Essentially those magic extensions will cause the parameters to be automatically rewritten. Example pseudo Rust code (note that CreateProcess starts with an optional application name followed by the application arguments):

// These arguments...
CreateProcess(None, @"foo.bat "hello world""@, ...);
// ...are rewritten as
CreateProcess(Some(r"C:\Windows\System32\cmd.exe"), @""foo.bat "hello world"""@, ...);

However, when setting the first parameter (the application name) as we now do, it will omit the extra level of quotes around the arguments:

// These arguments...
CreateProcess(Some("foo.bat"), @"foo.bat "hello world""@, ...);
// ...are rewritten as
CreateProcess(Some(r"C:\Windows\System32\cmd.exe"), @"foo.bat "hello world""@, ...);

This means the arguments won't be passed to the script as intended.

Note that running batch files this way is undocumented but people have relied on this so we probably shouldn't break it.

@rust-highfive
Copy link
Collaborator

r? @dtolnay

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 22, 2021
Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

Thanks!

@dtolnay
Copy link
Member

dtolnay commented Dec 22, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Dec 22, 2021

📌 Commit de764a7 has been approved by dtolnay

@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 Dec 22, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 23, 2021
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#88858 (Allow reverse iteration of lowercase'd/uppercase'd chars)
 - rust-lang#91544 (Fix duplicate derive clone suggestion)
 - rust-lang#92026 (Add some JSDoc comments to rustdoc JS)
 - rust-lang#92117 (kmc-solid: Add `std::sys::solid::fs::File::read_buf`)
 - rust-lang#92139 (Change Backtrace::enabled atomic from SeqCst to Relaxed)
 - rust-lang#92146 (Don't emit shared files when scraping examples from dependencies in Rustdoc)
 - rust-lang#92208 (Quote bat script command line)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3afed8f into rust-lang:master Dec 23, 2021
@rustbot rustbot added this to the 1.59.0 milestone Dec 23, 2021
@ChrisDenton ChrisDenton deleted the win-bat-cmd branch December 23, 2021 13:58
@Mark-Simulacrum Mark-Simulacrum added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jan 6, 2022
@Mark-Simulacrum
Copy link
Member

@m-ou-se m-ou-se added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Jan 6, 2022
@Mark-Simulacrum Mark-Simulacrum modified the milestones: 1.59.0, 1.58.0 Jan 7, 2022
@Mark-Simulacrum Mark-Simulacrum removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jan 7, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 8, 2022
…ulacrum

[beta] backports

Backports these PRs:

* Fix HashStable implementation on InferTy rust-lang#91892
* Revert setting a default for the MACOSX_DEPLOYMENT_TARGET env var for linking rust-lang#91870
* Make rustdoc headings black, and markdown blue rust-lang#91534
* Disable LLVM newPM by default rust-lang#91190
* Deduplicate projection sub-obligations rust-lang#90423
*  Sync portable-simd to remove autosplats rust-lang#91484 by dropping portable_simd entirely (keeping the subtree, just from std/core)
*  Quote bat script command line rust-lang#92208
* Fix failing tests rust-lang#92201 (CI fix)

r? `@Mark-Simulacrum`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken quote handling when spawning a process from a cmd script.
7 participants