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

Update documentation related to the recent cmd.exe fix #123709

Merged
merged 1 commit into from
May 19, 2024

Conversation

tgross35
Copy link
Contributor

Fix some grammar nits, change bat (extension) -> batch (file), and make line wrapping more consistent.

Fix some grammar nits, change `bat` (extension) -> `batch` (file), and
make line wrapping more consistent.
@rustbot
Copy link
Collaborator

rustbot commented Apr 10, 2024

r? @workingjubilee

rustbot has assigned @workingjubilee.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added O-windows Operating system: Windows 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 Apr 10, 2024
@tgross35
Copy link
Contributor Author

r? @ChrisDenton

Comment on lines +663 to 673
/// On Windows, use caution with untrusted inputs. Most applications use the
/// standard convention for decoding arguments passed to them. These are safe to
/// use with `arg`. However, some applications such as `cmd.exe` and `.bat` files
/// use a non-standard way of decoding arguments. They are therefore vulnerable
/// to malicious input.
///
/// In the case of `cmd.exe` this is especially important because a malicious
/// argument can potentially run arbitrary shell commands.
///
/// See [Windows argument splitting][windows-args] for more details
/// or [`raw_arg`] for manually implementing non-standard argument encoding.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Neither this nor the linked page really answer "I have untrusted input, how do I know if I can use it with .arg?". I think this could be improved but not really sure how (I didn't change it, just rewrapped).

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, and that's a tricky one to answer. I guess the short answer is you just have to know and trust the application/script that you're using uses MSVC compatible argument parsing rules. Which, I mean, is annoying. On the other hand sending untrusted arguments to an unknown application sounds wrong to me in any case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can put something like that into words, just explaining how Rust does quoting would help.

We now use the cmd quoting if the executable for Command::new is cmd.exe, *.bat or *.cmd, correct?

Copy link
Member

Choose a reason for hiding this comment

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

We don't for an explicit call to cmd.exe. We do for *.bat or *.cmd (case insensitive) as that's an implicit call to cmd.exe.

Note that we also don't prevent Linux users from using sh to execute things in the shell so that was not a goal here.

Copy link
Member

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

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

Chris should still review this.

//! On Unix systems arguments are passed to a new process as an array of strings
//! but on Windows arguments are passed as a single commandline string and it's
//! On Unix systems arguments are passed to a new process as an array of strings,
//! but on Windows arguments are passed as a single commandline string and it is
Copy link
Member

Choose a reason for hiding this comment

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

Commander Data, is that you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lol, the grammar lords always said to avoid short contractions in technical writing

@@ -107,26 +107,26 @@
//! * Use [`raw_arg`] to build a custom commandline. This bypasses the escaping
//! rules used by [`arg`] so should be used with due caution.
//!
//! `cmd.exe` and `.bat` use non-standard argument parsing and are especially
//! `cmd.exe` and `.bat` files use non-standard argument parsing and are especially
Copy link
Member

Choose a reason for hiding this comment

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

This makes it sound like "cmd.exe files" is a valid decomposition of the sentence's parts.

/// the standard C run-time escaping rules, such as `cmd.exe /c`.
///
/// # Bat files
/// # Batch files
Copy link
Member

Choose a reason for hiding this comment

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

There are many kinds of batch files used by many different job control languages. I believe only the .bat files of Windows are under discussion here. This retitling seems to be less correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the proper name is "DOS Batch file" but figured the DOS part is implied when discussing Windows. I have indeed seen "BAT File" though, just not 🦇

Copy link
Member

Choose a reason for hiding this comment

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

BAT file seems like the one we might prefer here, yes.

However, I must wonder... do all of these caveats apply to files with the .cmd extension also?

Copy link
Member

@workingjubilee workingjubilee Apr 10, 2024

Choose a reason for hiding this comment

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

The documentation so far doesn't seem to mention .cmd at all, despite that also being an applicable extension for Windows batch files with basically-the-same command language. I won't pretend to know what the exact caveats and corner cases are, though.

Copy link
Contributor Author

@tgross35 tgross35 Apr 10, 2024

Choose a reason for hiding this comment

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

However, I must wonder... do all of these caveats apply to files with the .cmd extension also?

Hey, according to wiki .cmd is just another "Batch File" 😄 https://en.wikipedia.org/wiki/Batch_file

(I'll take another read through and make sure both are covered appropriately)

Copy link
Member

Choose a reason for hiding this comment

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

Indeed!

I had a frisson of annoyance at that, as technically, there are many JCLs etc. etc. and then I realized that while indeed even in 2024 some people do use mainframes with such batch files that are not in the MS-DOS command language... everyone understands the meaning here from context, obviously.

@ChrisDenton
Copy link
Member

I'll get to reading this tomorrow but in the meantime I'd just like to say I'm grateful for all feedback. This was obviously written in secret with necessarily limited oversight so it didn't get the usual back-and-forth discussion from everyone.

@ChrisDenton
Copy link
Member

Sorry about my slowness here! I think this is definitely an improvement so I've approve on that basis. Maybe there's more to be done here but that will require some more thought and there's no reason to block this in the meantime.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented May 19, 2024

📌 Commit a7238b9 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 May 19, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request May 19, 2024
…mpiler-errors

Rollup of 7 pull requests

Successful merges:

 - rust-lang#123709 (Update documentation related to the recent cmd.exe fix)
 - rust-lang#124304 (revise the interpretation of ReadDir for HermitOS)
 - rust-lang#124708 (Actually use the `#[do_not_recommend]` attribute if present)
 - rust-lang#125252 (Add `#[inline]` to float `Debug` fallback used by `cfg(no_fp_fmt_parse)`)
 - rust-lang#125261 (crashes: add more)
 - rust-lang#125270 (Followup fixes from rust-lang#123344)
 - rust-lang#125275 (Migrate `run-make/rustdoc-scrape-examples-test` to new `rmake.rs`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0f923a4 into rust-lang:master May 19, 2024
11 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 19, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 19, 2024
Rollup merge of rust-lang#123709 - tgross35:windows-cmd-docs-update, r=ChrisDenton

Update documentation related to the recent cmd.exe fix

Fix some grammar nits, change `bat` (extension) -> `batch` (file), and make line wrapping more consistent.
@tgross35
Copy link
Contributor Author

Oh that’s on me, I meant to update a bit more but it slipped my mind. Thanks for the r!

@tgross35 tgross35 deleted the windows-cmd-docs-update branch July 16, 2024 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-windows Operating system: Windows 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