[PR #505] [MERGED] fix(win32): probe .cmd/.bat runtime shims via cmd.exe to avoid spawn EINVAL #2031

Closed
opened 2026-10-16 21:13:33 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/morluto/rea/pull/505
Author: @ahkurdev
Created: 10/5/2026
Status: ✅ Merged
Merged: 10/5/2026
Merged by: @morluto

Base: main ← Head: fix/win32-cmd-spawn-einval


📝 Commits (2)

  • 6022eca fix(win32): probe .cmd/.bat runtime shims via cmd.exe to avoid spawn EINVAL
  • 75b35a7 fix(win32): thread platform through version probe and harden batch quoting

📊 Changes

2 files changed (+143 additions, -7 deletions)

View changed files

📝 src/application/RuntimeExecutableDiagnostics.ts (+63 -7)
➕ src/application/RuntimeExecutableDiagnostics.win32.test.ts (+80 -0)

📄 Description

Problem

On Windows, rea doctor fails with { code: "UNKNOWN", message: "spawn EINVAL" } on Node >= 18.20 (verified on Node 26.7.0).

Node's CVE-2024-27980 mitigation blocks spawning .cmd/.bat files without a shell and throws EINVAL. On Windows the npm and npx PATH shims are .CMD files, so every runtime-toolchain probe of them fails with runtime_spawn_failed, and on some environments (e.g. when a batch shim is probed first) the whole doctor run reports spawn EINVAL.

Reproduction: on a healthy Windows x64 host with Node >= 20.12, run rea doctor — node-toolchains reports the npm/npx .CMD shims as failed probes.

Fix

Route batch-file candidates through cmd.exe /d /s /c:

  • windowsBatchCommand() detects .cmd/.bat candidates on win32 and builds a cmd.exe invocation with the whole command line as a single quoted argument
  • windowsVerbatimArguments: true prevents Node from re-quoting, so paths with spaces survive
  • non-batch paths keep the exact previous spawn behavior

Testing

  • New test RuntimeExecutableDiagnostics.win32.test.ts exercises real probes through the patched executeVersion and asserts no runtime_spawn_failed (EINVAL) — 2 passed
  • Existing Doctor.runtimeExecutables.test.ts — passed
  • tsc -p tsconfig.build.json --noEmit — clean
  • Prettier — formatted

Validated end-to-end on Windows 11 x64, Node 26.7.0: after the same patch (applied to the installed package) rea doctor reports node, node-toolchains, and host as healthy instead of spawn EINVAL / failed .CMD probes.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/morluto/rea/pull/505 **Author:** [@ahkurdev](https://github.com/ahkurdev) **Created:** 10/5/2026 **Status:** ✅ Merged **Merged:** 10/5/2026 **Merged by:** [@morluto](https://github.com/morluto) **Base:** `main` ← **Head:** `fix/win32-cmd-spawn-einval` --- ### 📝 Commits (2) - [`6022eca`](https://github.com/morluto/rea/commit/6022ecab16edffdbb0437b1079efebe5c0cbb280) fix(win32): probe .cmd/.bat runtime shims via cmd.exe to avoid spawn EINVAL - [`75b35a7`](https://github.com/morluto/rea/commit/75b35a7cc6fe27d3143c7b1a42baf71dd6ab2df7) fix(win32): thread platform through version probe and harden batch quoting ### 📊 Changes **2 files changed** (+143 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `src/application/RuntimeExecutableDiagnostics.ts` (+63 -7) ➕ `src/application/RuntimeExecutableDiagnostics.win32.test.ts` (+80 -0) </details> ### 📄 Description ## Problem On Windows, `rea doctor` fails with `{ code: "UNKNOWN", message: "spawn EINVAL" }` on Node >= 18.20 (verified on Node 26.7.0). Node's CVE-2024-27980 mitigation blocks spawning `.cmd`/`.bat` files without a shell and throws `EINVAL`. On Windows the `npm` and `npx` PATH shims are `.CMD` files, so every runtime-toolchain probe of them fails with `runtime_spawn_failed`, and on some environments (e.g. when a batch shim is probed first) the whole doctor run reports `spawn EINVAL`. Reproduction: on a healthy Windows x64 host with Node >= 20.12, run `rea doctor` — `node-toolchains` reports the npm/npx `.CMD` shims as failed probes. ## Fix Route batch-file candidates through `cmd.exe /d /s /c`: - `windowsBatchCommand()` detects `.cmd`/`.bat` candidates on win32 and builds a `cmd.exe` invocation with the whole command line as a single quoted argument - `windowsVerbatimArguments: true` prevents Node from re-quoting, so paths with spaces survive - non-batch paths keep the exact previous spawn behavior ## Testing - New test `RuntimeExecutableDiagnostics.win32.test.ts` exercises real probes through the patched `executeVersion` and asserts no `runtime_spawn_failed` (EINVAL) — 2 passed - Existing `Doctor.runtimeExecutables.test.ts` — passed - `tsc -p tsconfig.build.json --noEmit` — clean - Prettier — formatted Validated end-to-end on Windows 11 x64, Node 26.7.0: after the same patch (applied to the installed package) `rea doctor` reports `node`, `node-toolchains`, and `host` as healthy instead of `spawn EINVAL` / failed `.CMD` probes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-16 21:13:33 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#2031
No description provided.