Skip to content

Commit

Permalink
fix: codeQL issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kchindam-infy committed Jul 29, 2024
1 parent bb2523f commit 65a6845
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ const spawnWithShell = (cmd, args, opts, extra) => {
options.windowsVerbatimArguments = true
} else if (opts.isWSL) {
// handling for WSL
script = `${cmd} ${args.join(' ')}`
realArgs = ['-Command', script]
realArgs = ['-COmmand', 'Start-Process']
args.forEach(arg => {
realArgs.push(escapeWindowsArg(arg))

Check warning

Code scanning / CodeQL

Unsafe shell command constructed from library input Medium

This shell argument which depends on
library input
is later used in a
shell command
.
This shell argument which depends on
library input
is later used in a
shell command
.
This shell argument which depends on
library input
is later used in a
shell command
.
This shell argument which depends on
library input
is later used in a
shell command
.
})
} else {
for (const arg of args) {
script += ` ${escape.sh(arg)}`
Expand Down Expand Up @@ -157,9 +159,9 @@ const open = (_args, opts = {}, extra = {}) => {
// string immediately after the start command
if (isWSL) {
// For WSL, use wslpath to convert the path if necessary
command = 'powershell.exe -Command'
command = 'powershell.exe'
args = args.map(arg => `$(wslpath -w '${escapeWindowsArg(arg)}')`)
args.unshift('Start-Process')
args = args.map(arg => `"$(wslpath -w '${arg}')"`)
} else {
command = 'start ""'
}
Expand Down Expand Up @@ -220,4 +222,11 @@ const findInObject = (obj, key) => {
}
}

const escapeWindowsArg = (arg) => {
if (typeof arg !== 'string') {
return arg
}
return `${arg.replace(/"/g, '""')}"`
}

module.exports = promiseSpawn

0 comments on commit 65a6845

Please sign in to comment.