Process: fix Windows .cmd spawn EINVAL#29759
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d09f5aa8b5
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (WINDOWS_UNSAFE_CMD_CHARS_RE.test(arg)) { | ||
| throw new Error( | ||
| `Unsafe Windows cmd.exe argument detected: ${JSON.stringify(arg)}. ` + |
There was a problem hiding this comment.
Permit literal
% in cmd.exe-wrapped arguments
escapeForCmdExe now throws on any % (and &) when invoking .cmd/.bat via cmd.exe, but some existing Windows call paths pass user text as a single JSON argument (for example docsSearchCommand builds --args <payload> from the query in src/commands/docs.ts:174-178 and then runs via pnpm.cmd/npx.cmd). Queries like "100%" or "A & B" become hard failures (Unsafe Windows cmd.exe argument detected) before the subprocess starts, which is a functional regression from prior behavior for legitimate inputs.
Useful? React with 👍 / 👎.
Greptile SummaryFixes Windows EINVAL errors when spawning
Issue found: Confidence Score: 2/5
Last reviewed commit: d09f5aa |
src/process/exec.ts
Outdated
| const { stdout, stderr } = isWindowsBatchCommand(resolvedCommand) | ||
| ? await execFileAsync( | ||
| process.env.ComSpec ?? "cmd.exe", | ||
| ["/d", "/s", "/c", buildCmdExeCommandLine(resolvedCommand, args)], | ||
| options, | ||
| ) |
There was a problem hiding this comment.
missing windowsVerbatimArguments: true when spawning via cmd.exe wrapper
without this, Node.js will apply its own Windows quoting (using \" escapes) on top of the cmd.exe-style quoting (using "" escapes) from buildCmdExeCommandLine, causing malformed command lines
| const { stdout, stderr } = isWindowsBatchCommand(resolvedCommand) | |
| ? await execFileAsync( | |
| process.env.ComSpec ?? "cmd.exe", | |
| ["/d", "/s", "/c", buildCmdExeCommandLine(resolvedCommand, args)], | |
| options, | |
| ) | |
| const { stdout, stderr } = isWindowsBatchCommand(resolvedCommand) | |
| ? await execFileAsync( | |
| process.env.ComSpec ?? "cmd.exe", | |
| ["/d", "/s", "/c", buildCmdExeCommandLine(resolvedCommand, args)], | |
| { ...options, windowsVerbatimArguments: true }, | |
| ) |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/process/exec.ts
Line: 91-96
Comment:
missing `windowsVerbatimArguments: true` when spawning via cmd.exe wrapper
without this, Node.js will apply its own Windows quoting (using `\"` escapes) on top of the cmd.exe-style quoting (using `""` escapes) from `buildCmdExeCommandLine`, causing malformed command lines
```suggestion
const { stdout, stderr } = isWindowsBatchCommand(resolvedCommand)
? await execFileAsync(
process.env.ComSpec ?? "cmd.exe",
["/d", "/s", "/c", buildCmdExeCommandLine(resolvedCommand, args)],
{ ...options, windowsVerbatimArguments: true },
)
```
How can I resolve this? If you propose a fix, please make it concise.44dd446 to
de82564
Compare
|
PR #29759 - Process: fix Windows .cmd spawn EINVAL (#29759) Merged via squash.
Thanks @icesword0760! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: de82564fd0
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
|
||
| function escapeForCmdExe(arg: string): string { | ||
| // Reject cmd metacharacters to avoid injection when we must pass a single command line. | ||
| if (WINDOWS_UNSAFE_CMD_CHARS_RE.test(arg)) { |
There was a problem hiding this comment.
Allow
% and & in wrapped cmd.exe arguments
escapeForCmdExe now throws for any argument containing % or &, but several Windows call paths pass user text through argv (for example docsSearchCommand serializes the raw query into the --args JSON payload before invoking pnpm.cmd). Inputs like 100% or A & B therefore fail before the subprocess even starts, which is a functional regression for legitimate queries and command arguments; these characters need escaping in the wrapper path rather than blanket rejection.
Useful? React with 👍 / 👎.
…ord0760 Verified: - pnpm vitest run src/process/exec.test.ts src/process/exec.windows.test.ts Co-authored-by: icesword0760 <123886211+icesword0760@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
Verified: - pnpm vitest run src/process/exec.test.ts src/process/exec.windows.test.ts Co-authored-by: icesword0760 <123886211+icesword0760@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…ord0760 Verified: - pnpm vitest run src/process/exec.test.ts src/process/exec.windows.test.ts Co-authored-by: icesword0760 <123886211+icesword0760@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…ord0760 Verified: - pnpm vitest run src/process/exec.test.ts src/process/exec.windows.test.ts Co-authored-by: icesword0760 <123886211+icesword0760@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…ord0760 Verified: - pnpm vitest run src/process/exec.test.ts src/process/exec.windows.test.ts Co-authored-by: icesword0760 <123886211+icesword0760@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…ord0760 Verified: - pnpm vitest run src/process/exec.test.ts src/process/exec.windows.test.ts Co-authored-by: icesword0760 <123886211+icesword0760@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
…ord0760 Verified: - pnpm vitest run src/process/exec.test.ts src/process/exec.windows.test.ts Co-authored-by: icesword0760 <123886211+icesword0760@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
Summary
Test plan
pnpm test exec.test.ts