Skip to content
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

Enable shell on Windows #131

Merged
merged 5 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"mkdirp": "3.0.1",
"node-downloader-helper": "2.1.9",
"progress": "2.0.3",
"shell-quote": "1.8.1",
"slugify": "1.6.6"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const os = require('os');
const fs = require('fs');
const log = require('fancy-log');
const { HttpsProxyAgent } = require('https-proxy-agent');
const { isWindows } = require('./utils/platform');

module.exports.getScannerParams = getScannerParams;
module.exports.extendWithExecParams = extendWithExecParams;
Expand Down Expand Up @@ -195,5 +196,6 @@ function extendWithExecParams(env = {}) {
// (if this value is exceeded then the child process is killed).
// TODO: make this customizable
maxBuffer: ONE_MB,
shell: isWindows(), //we need to enable sheel on windows due to CVE-2024-27980
vdiez marked this conversation as resolved.
Show resolved Hide resolved
};
}
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

const quote = require('shell-quote').quote;
const exec = require('child_process').execFileSync;
const log = require('fancy-log');
const { getScannerParams, extendWithExecParams } = require('./config');
Expand All @@ -37,7 +36,7 @@ async function scan(params, cliArgs = [], localScanner = false) {
// prepare the exec options, most notably with the SQ params
const scannerParams = getScannerParams(process.cwd(), params);
const execOptions = extendWithExecParams(scannerParams);
exec(quote([sqScannerCommand]), fromParam().concat(cliArgs), execOptions);
exec(sqScannerCommand, fromParam().concat(cliArgs), execOptions);
log('Analysis finished.');
}

Expand Down
3 changes: 1 addition & 2 deletions src/sonar-scanner-executable.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

const quote = require('shell-quote').quote;
const exec = require('child_process').execFileSync;
const mkdirs = require('mkdirp').sync;
const { DownloaderHelper } = require('node-downloader-helper');
Expand Down Expand Up @@ -121,7 +120,7 @@ async function getSonarScannerExecutable(params = {}) {
function getLocalSonarScannerExecutable(command = 'sonar-scanner') {
try {
log(`Trying to find a local install of the SonarScanner: ${command}`);
exec(quote([command]), ['-v']);
exec(command, ['-v'], { shell: true });
// TODO: we should check that it's at least v2.8+
log('Local install of Sonarscanner found.');
return command;
Expand Down
4 changes: 3 additions & 1 deletion test/unit/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const {
SONAR_SCANNER_MIRROR,
} = require('../../src/config');
const { buildInstallFolderPath, buildExecutablePath } = require('../../src/utils/paths');
const { findTargetOS } = require('../../src/utils/platform');
const { findTargetOS, isWindows } = require('../../src/utils/platform');

function pathForProject(projectFolder) {
return path.join(__dirname, 'fixtures', projectFolder);
Expand Down Expand Up @@ -279,6 +279,7 @@ describe('config', function () {
assert.deepEqual(extendWithExecParams({ hello: 2 }), {
maxBuffer: 1024 * 1024,
stdio: 'inherit',
shell: isWindows(),
env: {
hello: 2,
whatsup: 'dog',
Expand All @@ -292,6 +293,7 @@ describe('config', function () {
assert.deepEqual(extendWithExecParams(), {
env: {},
maxBuffer: 1024 * 1024,
shell: isWindows(),
stdio: 'inherit',
});
});
Expand Down