Skip to content

Commit fb94af9

Browse files
committed
remove the last dependency on PrettyPrinting
1 parent 051de24 commit fb94af9

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

javascript/ql/src/semmle/javascript/security/UselessUseOfCat.qll

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,10 @@ class UselessCat extends CommandCall {
9393
UselessCat() {
9494
this = command and
9595
isACallTo(getACatExecuteable()) and
96-
// There is a file to read, and not just a pair of quotes.
97-
(
98-
not exists(PrettyPrintCatCall::createFileArgument(this))
99-
or
100-
exists(string fileArg | fileArg = PrettyPrintCatCall::createFileArgument(this) |
101-
fileArg.length() >= 3
102-
)
96+
// There is a file to read, it's not just spawning `cat`.
97+
not (
98+
not exists(getArgumentList()) and
99+
getArgument(0).mayHaveStringValue(getACatExecuteable())
103100
) and
104101
// wildcards, pipes, redirections, other bash features, and multiple files (spaces) are OK.
105102
not exists(getNonCommandConstantString().regexpFind("\\*|\\||>|<| |\\$|&|,|\\`", _, _)) and

javascript/ql/test/query-tests/Security/CWE-078/UselessUseOfCat.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ syncCommand
4545
| tst_shell-command-injection-from-environment.js:5:2:5:54 | cp.exec ... temp")) |
4646
| uselesscat.js:16:1:16:29 | execSyn ... uinfo') |
4747
| uselesscat.js:18:1:18:26 | execSyn ... path}`) |
48-
| uselesscat.js:20:1:20:50 | child_p ... wc -l') |
48+
| uselesscat.js:20:1:20:36 | execSyn ... wc -l') |
4949
| uselesscat.js:22:1:22:38 | execSyn ... o/bar') |
5050
| uselesscat.js:24:1:24:35 | execSyn ... o/bar`) |
5151
| uselesscat.js:28:1:28:39 | execSyn ... 1000}) |

javascript/ql/test/query-tests/Security/CWE-078/uselesscat.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ execSync('cat /proc/cpuinfo').toString(); // NOT OK.
1717

1818
execSync(`cat ${newpath}`) // NOT OK
1919

20-
child_process.execSync('cat package.json | wc -l'); // OK - pipes!
20+
execSync('cat package.json | wc -l'); // OK - pipes!
2121

2222
execSync('cat /proc/cpuinfo /foo/bar').toString(); // OK multiple files.
2323

@@ -135,4 +135,8 @@ console.log(notDead);
135135

136136
const stdout2 = execSync('cat /etc/dnsmasq.conf', { // NOT OK.
137137
encoding: 'utf8'
138-
});
138+
});
139+
140+
exec('/bin/cat', function (e, s) {}); // OK
141+
142+
spawn("cat") // OK

0 commit comments

Comments
 (0)