-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Potential fix for code scanning alert no. 8: Unsafe shell command constructed from library input #610
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
Potential fix for code scanning alert no. 8: Unsafe shell command constructed from library input #610
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,16 +59,36 @@ class WindowsSystemShell extends SystemShell { | |
| ps.dispose() | ||
| } | ||
| } else { | ||
| let compose = 'chcp 65001' // 'chcp 65001 ' | ||
| await childExecCmdWindows('chcp 65001', args) | ||
| let ret | ||
| for (const cmd of cmds) { | ||
| compose += ` && ${cmd}` | ||
| ret = await childExecCmdWindows(cmd, args) | ||
| } | ||
| // compose += '&& exit' | ||
| return await childExec(compose, args) | ||
| return ret | ||
|
Comment on lines
+62
to
+67
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| function childExecCmdWindows (cmd, options = {}) { | ||
| return new Promise((resolve, reject) => { | ||
| const execOptions = { ...options } | ||
| delete execOptions.type | ||
| delete execOptions.printErrorLog | ||
|
|
||
| log.info('shell:', cmd) | ||
| childProcess.execFile('cmd.exe', ['/d', '/s', '/c', cmd], execOptions, (error, stdout, stderr) => { | ||
| if (error) { | ||
|
Comment on lines
+72
to
+80
|
||
| if (options.printErrorLog !== false) { | ||
| log.error('cmd 命令执行错误:\n===>\ncommands:', cmd, '\n error:', error, '\n<===') | ||
| } | ||
| reject(new Error(stderr)) | ||
| } else { | ||
| resolve(stdout.replace('Active code page: 65001\r\n', '')) | ||
| } | ||
| }) | ||
| }) | ||
| } | ||
|
|
||
| function childExec (composeCmds, options = {}) { | ||
| return new Promise((resolve, reject) => { | ||
| log.info('shell:', composeCmds) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chcp 65001is now executed in a separatecmd.exeprocess, so the code page change won’t persist for the subsequent command executions (eachchildExecCmdWindowscall spawns a new process). This likely regresses the original intent of ensuring UTF-8 output for the actual commands; consider running thechcp 65001step in the same invocation as each command (or otherwise ensuring the code page is set for the process that runs the command).