66import javascript
77private import ApiGraphs
88
9+ private predicate execApi ( string mod , string fn , int cmdArg , int optionsArg , boolean shell ) {
10+ mod = "cross-spawn" and
11+ fn = "sync" and
12+ cmdArg = 0 and
13+ shell = false and
14+ optionsArg = - 1
15+ or
16+ mod = "execa" and
17+ optionsArg = - 1 and
18+ (
19+ shell = false and
20+ (
21+ fn = "node" or
22+ fn = "shell" or
23+ fn = "shellSync" or
24+ fn = "stdout" or
25+ fn = "stderr" or
26+ fn = "sync"
27+ )
28+ or
29+ shell = true and
30+ ( fn = "command" or fn = "commandSync" )
31+ ) and
32+ cmdArg = 0
33+ }
34+
35+ private predicate execApi ( string mod , int cmdArg , int optionsArg , boolean shell ) {
36+ shell = false and
37+ (
38+ mod = "cross-spawn" and cmdArg = 0 and optionsArg = - 1
39+ or
40+ mod = "cross-spawn-async" and cmdArg = 0 and optionsArg = - 1
41+ or
42+ mod = "exec-async" and cmdArg = 0 and optionsArg = - 1
43+ or
44+ mod = "execa" and cmdArg = 0 and optionsArg = - 1
45+ )
46+ or
47+ shell = true and
48+ (
49+ mod = "exec" and
50+ optionsArg = - 2 and
51+ cmdArg = 0
52+ or
53+ mod = "remote-exec" and
54+ cmdArg = 1 and
55+ optionsArg = - 1
56+ )
57+ }
58+
959private class SystemCommandExecutors extends SystemCommandExecution , DataFlow:: InvokeNode {
1060 int cmdArg ;
1161 int optionsArg ; // either a positive number representing the n'th argument, or a negative number representing the n'th last argument (e.g. -2 is the second last argument).
@@ -14,70 +64,20 @@ private class SystemCommandExecutors extends SystemCommandExecution, DataFlow::I
1464
1565 SystemCommandExecutors ( ) {
1666 exists ( string mod , API:: Feature callee |
17- exists ( string method |
18- mod = "cross-spawn" and
19- method = "sync" and
20- cmdArg = 0 and
21- shell = false and
22- optionsArg = - 1
23- or
24- mod = "execa" and
25- optionsArg = - 1 and
26- (
27- shell = false and
28- (
29- method = "shell" or
30- method = "shellSync" or
31- method = "stdout" or
32- method = "stderr" or
33- method = "sync"
34- )
35- or
36- shell = true and
37- ( method = "command" or method = "commandSync" )
38- ) and
39- cmdArg = 0
40- or
41- mod = "execa" and
42- method = "node" and
43- cmdArg = 0 and
44- optionsArg = 1 and
45- shell = false
46- |
47- callee = API:: moduleImport ( mod ) .getMember ( method ) and
48- sync = getSync ( method )
67+ exists ( string fn |
68+ execApi ( mod , fn , cmdArg , optionsArg , shell ) and
69+ sync = getSync ( fn ) and
70+ callee = API:: moduleImport ( mod ) .getMember ( fn )
4971 )
5072 or
73+ execApi ( mod , cmdArg , optionsArg , shell ) and
5174 sync = false and
52- (
53- shell = false and
54- (
55- mod = "cross-spawn" and cmdArg = 0 and optionsArg = - 1
56- or
57- mod = "cross-spawn-async" and cmdArg = 0 and optionsArg = - 1
58- or
59- mod = "exec-async" and cmdArg = 0 and optionsArg = - 1
60- or
61- mod = "execa" and cmdArg = 0 and optionsArg = - 1
62- )
63- or
64- shell = true and
65- (
66- mod = "exec" and
67- optionsArg = - 2 and
68- cmdArg = 0
69- or
70- mod = "remote-exec" and
71- cmdArg = 1 and
72- optionsArg = - 1
73- )
74- ) and
7575 callee = API:: moduleImport ( mod )
7676 |
7777 this = callee .getReturn ( ) .getAUse ( )
7878 )
7979 or
80- this = DataFlow :: moduleImport ( "foreground-child" ) .getACall ( ) and
80+ this = API :: moduleImport ( "foreground-child" ) .getReturn ( ) . getAUse ( ) and
8181 cmdArg = 0 and
8282 optionsArg = 1 and
8383 shell = false and
@@ -121,19 +121,19 @@ private class RemoteCommandExecutor extends SystemCommandExecution, DataFlow::In
121121 int cmdArg ;
122122
123123 RemoteCommandExecutor ( ) {
124- this = DataFlow :: moduleImport ( "remote-exec" ) .getACall ( ) and
124+ this = API :: moduleImport ( "remote-exec" ) .getReturn ( ) . getAUse ( ) and
125125 cmdArg = 1
126126 or
127- exists ( DataFlow :: SourceNode ssh2 , DataFlow :: SourceNode client |
128- ssh2 = DataFlow :: moduleImport ( "ssh2" ) and
129- ( client = ssh2 or client = ssh2 .getAPropertyRead ( "Client" ) ) and
130- this = client .getAnInstantiation ( ) .getAMethodCall ( "exec" ) and
127+ exists ( API :: Feature ssh2 , API :: Feature client |
128+ ssh2 = API :: moduleImport ( "ssh2" ) and
129+ client in [ ssh2 , ssh2 .getMember ( "Client" ) ] and
130+ this = client .getInstance ( ) .getMember ( "exec" ) . getReturn ( ) . getAUse ( ) and
131131 cmdArg = 0
132132 )
133133 or
134- exists ( DataFlow :: SourceNode ssh2stream |
135- ssh2stream = DataFlow :: moduleMember ( "ssh2-streams" , "SSH2Stream" ) and
136- this = ssh2stream .getAnInstantiation ( ) .getAMethodCall ( "exec" ) and
134+ exists ( API :: Feature ssh2stream |
135+ ssh2stream = API :: moduleImport ( "ssh2-streams" ) . getMember ( "SSH2Stream" ) and
136+ this = ssh2stream .getInstance ( ) .getMember ( "exec" ) . getReturn ( ) . getAUse ( ) and
137137 cmdArg = 1
138138 )
139139 }
@@ -148,7 +148,7 @@ private class RemoteCommandExecutor extends SystemCommandExecution, DataFlow::In
148148}
149149
150150private class Opener extends SystemCommandExecution , DataFlow:: InvokeNode {
151- Opener ( ) { this = DataFlow :: moduleImport ( "opener" ) .getACall ( ) }
151+ Opener ( ) { this = API :: moduleImport ( "opener" ) .getReturn ( ) . getAUse ( ) }
152152
153153 override DataFlow:: Node getACommandArgument ( ) { result = getOptionArgument ( 1 , "command" ) }
154154
0 commit comments