Skip to content

Commit 539ef49

Browse files
committed
change join order for SystemCommandExecutors - and use ApiGraphs::getACall
1 parent 56405f4 commit 539ef49

File tree

1 file changed

+27
-32
lines changed

1 file changed

+27
-32
lines changed

javascript/ql/src/semmle/javascript/frameworks/SystemCommandExecutors.qll

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,29 @@
55

66
import javascript
77

8-
private predicate execApi(string mod, string fn, int cmdArg, int optionsArg, boolean shell) {
9-
mod = "cross-spawn" and
10-
fn = "sync" and
11-
cmdArg = 0 and
12-
shell = false and
13-
optionsArg = -1
14-
or
15-
mod = "execa" and
16-
optionsArg = -1 and
8+
pragma[noinline]
9+
private predicate execApi(
10+
string mod, string fn, int cmdArg, int optionsArg, boolean shell, boolean sync
11+
) {
12+
sync = getSync(fn) and
1713
(
14+
mod = "cross-spawn" and
15+
fn = "sync" and
16+
cmdArg = 0 and
1817
shell = false and
19-
(
20-
fn = "node" or
21-
fn = "stdout" or
22-
fn = "stderr" or
23-
fn = "sync"
24-
)
18+
optionsArg = -1
2519
or
26-
shell = true and
20+
mod = "execa" and
21+
optionsArg = -1 and
2722
(
28-
fn = "command" or
29-
fn = "commandSync" or
30-
fn = "shell" or
31-
fn = "shellSync"
32-
)
33-
) and
34-
cmdArg = 0
23+
shell = false and
24+
fn = ["node", "stdout", "stderr", "sync"]
25+
or
26+
shell = true and
27+
fn = ["command", "commandSync", "shell", "shellSync"]
28+
) and
29+
cmdArg = 0
30+
)
3531
}
3632

3733
private predicate execApi(string mod, int cmdArg, int optionsArg, boolean shell) {
@@ -61,17 +57,16 @@ private class SystemCommandExecutors extends SystemCommandExecution, DataFlow::I
6157
SystemCommandExecutors() {
6258
exists(string mod |
6359
exists(string fn |
64-
execApi(mod, fn, cmdArg, optionsArg, shell) and
65-
sync = getSync(fn) and
66-
this = API::moduleImport(mod).getMember(fn).getReturn().getAUse()
60+
execApi(mod, fn, cmdArg, optionsArg, shell, sync) and
61+
this = API::moduleImport(mod).getMember(fn).getAnInvocation()
6762
)
6863
or
6964
execApi(mod, cmdArg, optionsArg, shell) and
7065
sync = false and
71-
this = API::moduleImport(mod).getReturn().getAUse()
66+
this = API::moduleImport(mod).getAnInvocation()
7267
)
7368
or
74-
this = API::moduleImport("foreground-child").getReturn().getAUse() and
69+
this = API::moduleImport("foreground-child").getACall() and
7570
cmdArg = 0 and
7671
optionsArg = 1 and
7772
shell = false and
@@ -115,19 +110,19 @@ private class RemoteCommandExecutor extends SystemCommandExecution, DataFlow::In
115110
int cmdArg;
116111

117112
RemoteCommandExecutor() {
118-
this = API::moduleImport("remote-exec").getReturn().getAUse() and
113+
this = API::moduleImport("remote-exec").getACall() and
119114
cmdArg = 1
120115
or
121116
exists(API::Node ssh2, API::Node client |
122117
ssh2 = API::moduleImport("ssh2") and
123118
client in [ssh2, ssh2.getMember("Client")] and
124-
this = client.getInstance().getMember("exec").getReturn().getAUse() and
119+
this = client.getInstance().getMember("exec").getACall() and
125120
cmdArg = 0
126121
)
127122
or
128123
exists(API::Node ssh2stream |
129124
ssh2stream = API::moduleImport("ssh2-streams").getMember("SSH2Stream") and
130-
this = ssh2stream.getInstance().getMember("exec").getReturn().getAUse() and
125+
this = ssh2stream.getInstance().getMember("exec").getACall() and
131126
cmdArg = 1
132127
)
133128
}
@@ -142,7 +137,7 @@ private class RemoteCommandExecutor extends SystemCommandExecution, DataFlow::In
142137
}
143138

144139
private class Opener extends SystemCommandExecution, DataFlow::InvokeNode {
145-
Opener() { this = API::moduleImport("opener").getReturn().getAUse() }
140+
Opener() { this = API::moduleImport("opener").getACall() }
146141

147142
override DataFlow::Node getACommandArgument() { result = getOptionArgument(1, "command") }
148143

0 commit comments

Comments
 (0)