Skip to content

Commit 7a5288a

Browse files
committed
🤖 fix: use eval with command substitution to avoid stdin issues
Scripts containing 'exec </dev/null' would break when piped to bash via 'echo BASE64 | base64 -d | bash' because the stdin redirection would cut off bash's ability to read the rest of the script. Solution: Use 'eval "$(echo BASE64 | base64 -d)"' which captures the entire decoded script via command substitution before executing it. This way stdin redirection in the script doesn't affect script reading.
1 parent 5abbe09 commit 7a5288a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/node/utils/main/bashPath.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,13 @@ export function getSpawnConfig(runtime: BashRuntime, script: string, cwd?: strin
397397
// 1. Base64 only contains [A-Za-z0-9+/=] - no special chars
398398
// 2. The decode happens inside bash, so PowerShell never sees the script
399399
// 3. Single quotes in PowerShell pass the string literally to WSL
400+
//
401+
// IMPORTANT: Use eval "$(echo ... | base64 -d)" instead of "echo ... | base64 -d | bash"
402+
// The latter pipes to bash's stdin, which breaks if the script contains "exec </dev/null"
403+
// (that redirects stdin to /dev/null, cutting off the script mid-read).
404+
// Using eval with command substitution captures the entire decoded script first.
400405
const wslArgs = runtime.distro ? `-d ${runtime.distro}` : "";
401-
const psCommand = `wsl ${wslArgs} bash -c 'echo ${base64Script} | base64 -d | bash'`.trim();
406+
const psCommand = `wsl ${wslArgs} bash -c 'eval "$(echo ${base64Script} | base64 -d)"'`.trim();
402407

403408
return {
404409
command: psPath,

0 commit comments

Comments
 (0)