Skip to content

Commit 18cea2d

Browse files
committed
Added support for shelljs.cmd and async-shelljs.asyncExec
1 parent 25d04f1 commit 18cea2d

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

javascript/ql/lib/semmle/javascript/frameworks/ShellJS.qll

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module ShellJS {
1515
.getMember([
1616
"exec", "cd", "cp", "touch", "chmod", "pushd", "find", "ls", "ln", "mkdir", "mv",
1717
"rm", "cat", "head", "sort", "tail", "uniq", "grep", "sed", "to", "toEnd", "echo",
18-
"which",
18+
"which", "cmd", "asyncExec"
1919
])
2020
.getReturn()
2121
}
@@ -154,16 +154,27 @@ module ShellJS {
154154
}
155155

156156
/**
157-
* A call to `shelljs.exec()` modeled as command execution.
157+
* A call to `shelljs.exec()`, `shelljs.cmd()`, or `async-shelljs.asyncExec()` modeled as command execution.
158158
*/
159159
private class ShellJSExec extends SystemCommandExecution, ShellJSCall {
160-
ShellJSExec() { name = "exec" }
161-
162-
override DataFlow::Node getACommandArgument() { result = this.getArgument(0) }
160+
ShellJSExec() { name = ["exec", "cmd", "asyncExec"] }
161+
162+
override DataFlow::Node getACommandArgument() {
163+
if name = "cmd"
164+
then
165+
result = this.getArgument(_) and
166+
not (
167+
result = this.getLastArgument() and
168+
exists(this.getOptionsArg())
169+
)
170+
else
171+
// For exec/asyncExec: only first argument is command
172+
result = this.getArgument(0)
173+
}
163174

164175
override predicate isShellInterpreted(DataFlow::Node arg) { arg = this.getACommandArgument() }
165176

166-
override predicate isSync() { none() }
177+
override predicate isSync() { name = "cmd" }
167178

168179
override DataFlow::Node getOptionsArg() {
169180
result = this.getLastArgument() and

javascript/ql/test/library-tests/frameworks/Shelljs/ShellJS.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ test_SystemCommandExecution
6161
| tst.js:14:1:14:27 | shelljs ... ts, cb) |
6262
| tst.js:60:1:60:51 | shelljs ... ec(cmd) |
6363
| tst.js:61:1:61:27 | shelljs ... ec(cmd) |
64+
| tst.js:63:1:63:37 | shelljs ... ptions) |
65+
| tst.js:64:1:64:16 | shelljs.cmd(cmd) |
66+
| tst.js:68:1:68:36 | shelljs ... ts, cb) |
6467
test_FileNameSource
6568
| tst.js:15:1:15:26 | shelljs ... file2) |
6669
| tst.js:24:1:24:16 | shelljs.ls(file) |

0 commit comments

Comments
 (0)