Skip to content

Commit

Permalink
Enable shell on Windows (#131)
Browse files Browse the repository at this point in the history
Co-authored-by: Ilia Kebets <104737176+ilia-kebets-sonarsource@users.noreply.github.com>
  • Loading branch information
vdiez and ilia-kebets-sonarsource authored Apr 26, 2024
1 parent aa32e71 commit 3779734
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 12 deletions.
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 shell on windows due to CVE-2024-27980
};
}
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

0 comments on commit 3779734

Please sign in to comment.