Skip to content

Commit

Permalink
Removes false positive on non-win32 platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanis committed Sep 29, 2021
1 parent 1c92d69 commit 82cc04b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/cli/commands/policies.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* @flow */
/* eslint-disable max-len */

import type {Reporter} from '../../reporters/index.js';
import type Config from '../../config.js';
Expand Down
16 changes: 9 additions & 7 deletions src/util/child.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ export const exec = promisify(child.exec);

function validate(program: string, opts?: Object = {}) {
if (program.includes('/')) {
return true;
return;
}

const cwd = opts.cwd || process.cwd();
const pathext = process.env.PATHEXT || '';
if (process.platform === 'win32' && process.env.PATHEXT) {
const cwd = opts.cwd || process.cwd();
const pathext = process.env.PATHEXT;

for (const ext of pathext.split(';')) {
const candidate = path.join(cwd, `${program}${ext}`);
if (fs.existsSync(candidate)) {
throw new Error(`Potentially dangerous call to "${program}" in ${cwd}`);
for (const ext of pathext.split(';')) {
const candidate = path.join(cwd, `${program}${ext}`);
if (fs.existsSync(candidate)) {
throw new Error(`Potentially dangerous call to "${program}" in ${cwd}`);
}
}
}
}
Expand Down

0 comments on commit 82cc04b

Please sign in to comment.