@@ -90,17 +90,96 @@ class RunnerEntrypoint extends Function {
90
90
}
91
91
}
92
92
93
+ /**
94
+ * A generic check to see if we are in actions or runner mode in a particular block of code.
95
+ */
96
+ abstract class ActionsGuard extends IfStmt {
97
+
98
+ /**
99
+ * Get an expr that is only executed on actions
100
+ */
101
+ abstract Expr getAnActionsExpr ( ) ;
102
+ }
103
+
104
+ /**
105
+ * A check of whether we are in actions mode or runner mode, based on
106
+ * the presense of a call to `isActions()` in the condition of an if statement.
107
+ */
108
+ class IsActionsGuard extends ActionsGuard {
109
+ IsActionsGuard ( ) {
110
+ getCondition ( ) .( CallExpr ) .getCalleeName ( ) = "isActions"
111
+ }
112
+
113
+ /**
114
+ * Get the "then" block that is the "actions" path.
115
+ */
116
+ Stmt getActionsBlock ( ) {
117
+ result = getThen ( )
118
+ }
119
+
120
+ /**
121
+ * Get an expr that is only executed on actions
122
+ */
123
+ override Expr getAnActionsExpr ( ) {
124
+ getActionsBlock ( ) .getAChildStmt * ( ) .getAChildExpr * ( ) = result
125
+ }
126
+ }
127
+
128
+ /**
129
+ * A check of whether we are in actions mode or runner mode, based on
130
+ * the presense of a call to `!isActions()` in the condition of an if statement.
131
+ */
132
+ class NegatedIsActionsGuard extends ActionsGuard {
133
+ NegatedIsActionsGuard ( ) {
134
+ getCondition ( ) .( LogNotExpr ) .getOperand ( ) .( CallExpr ) .getCalleeName ( ) = "isActions"
135
+ }
136
+
137
+ /**
138
+ * Get the "else" block that is the "actions" path.
139
+ */
140
+ Stmt getActionsBlock ( ) {
141
+ result = getElse ( )
142
+ }
143
+
144
+ /**
145
+ * Get an expr that is only executed on actions
146
+ */
147
+ override Expr getAnActionsExpr ( ) {
148
+ getActionsBlock ( ) .getAChildStmt * ( ) .getAChildExpr * ( ) = result
149
+ }
150
+ }
151
+
152
+ class ModeAccess extends PropAccess {
153
+ ModeAccess ( ) {
154
+ (
155
+ // eg- Mode.actions
156
+ getBase ( ) .( Identifier ) .getName ( ) = "Mode" or
157
+ // eg- actionUtil.Mode.actions
158
+ getBase ( ) .( PropAccess ) .getPropertyName ( ) = "Mode"
159
+ ) and
160
+ ( getPropertyName ( ) = "actions" or getPropertyName ( ) = "runner" )
161
+ }
162
+
163
+ predicate isActions ( ) {
164
+ getPropertyName ( ) = "actions"
165
+ }
166
+
167
+ predicate isRunner ( ) {
168
+ getPropertyName ( ) = "runner"
169
+ }
170
+ }
171
+
93
172
/**
94
173
* A check of whether we are in actions mode or runner mode.
95
174
*/
96
- class ModeGuard extends IfStmt {
175
+ class ModeGuard extends ActionsGuard {
97
176
ModeGuard ( ) {
98
- getCondition ( ) .( EqualityTest ) .getAnOperand ( ) .( StringLiteral ) . getValue ( ) = "actions" or
99
- getCondition ( ) .( EqualityTest ) .getAnOperand ( ) .( StringLiteral ) . getValue ( ) = "runner"
177
+ getCondition ( ) .( EqualityTest ) .getAnOperand ( ) .( ModeAccess ) . isActions ( ) or
178
+ getCondition ( ) .( EqualityTest ) .getAnOperand ( ) .( ModeAccess ) . isRunner ( )
100
179
}
101
180
102
- string getOperand ( ) {
103
- result = getCondition ( ) .( EqualityTest ) .getAnOperand ( ) . ( StringLiteral ) . getValue ( )
181
+ ModeAccess getOperand ( ) {
182
+ result = getCondition ( ) .( EqualityTest ) .getAnOperand ( )
104
183
}
105
184
106
185
predicate isPositive ( ) {
@@ -111,19 +190,19 @@ class ModeGuard extends IfStmt {
111
190
* Get the then or else block that is the "actions" path.
112
191
*/
113
192
Stmt getActionsBlock ( ) {
114
- ( getOperand ( ) = "actions" and isPositive ( ) and result = getThen ( ) )
193
+ ( getOperand ( ) . isActions ( ) and isPositive ( ) and result = getThen ( ) )
115
194
or
116
- ( getOperand ( ) = "runner" and not isPositive ( ) and result = getThen ( ) )
195
+ ( getOperand ( ) . isRunner ( ) and not isPositive ( ) and result = getThen ( ) )
117
196
or
118
- ( getOperand ( ) = "actions" and not isPositive ( ) and result = getElse ( ) )
197
+ ( getOperand ( ) . isActions ( ) and not isPositive ( ) and result = getElse ( ) )
119
198
or
120
- ( getOperand ( ) = "runner" and isPositive ( ) and result = getElse ( ) )
199
+ ( getOperand ( ) . isRunner ( ) and isPositive ( ) and result = getElse ( ) )
121
200
}
122
201
123
202
/**
124
203
* Get an expr that is only executed on actions
125
204
*/
126
- Expr getAnActionsExpr ( ) {
205
+ override Expr getAnActionsExpr ( ) {
127
206
getActionsBlock ( ) .getAChildStmt * ( ) .getAChildExpr * ( ) = result
128
207
}
129
208
}
@@ -133,7 +212,7 @@ class ModeGuard extends IfStmt {
133
212
* and is not only called on actions.
134
213
*/
135
214
Expr getAFunctionChildExpr ( Function f ) {
136
- not exists ( ModeGuard guard | guard .getAnActionsExpr ( ) = result ) and
215
+ not exists ( ActionsGuard guard | guard .getAnActionsExpr ( ) = result ) and
137
216
result .getContainer ( ) = f
138
217
}
139
218
@@ -145,16 +224,16 @@ Function calledBy(Function f) {
145
224
exists ( InvokeExpr invokeExpr |
146
225
invokeExpr = getAFunctionChildExpr ( f ) and
147
226
invokeExpr .getResolvedCallee ( ) = result and
148
- not exists ( ModeGuard guard | guard .getAnActionsExpr ( ) = invokeExpr )
227
+ not exists ( ActionsGuard guard | guard .getAnActionsExpr ( ) = invokeExpr )
149
228
)
150
229
or
151
230
// Assume outer function causes inner function to be called
152
231
( result instanceof Expr and
153
232
result .getEnclosingContainer ( ) = f and
154
- not exists ( ModeGuard guard | guard .getAnActionsExpr ( ) = result ) )
233
+ not exists ( ActionsGuard guard | guard .getAnActionsExpr ( ) = result ) )
155
234
}
156
235
157
- from VarAccess v , ActionsLibImport actionsLib , RunnerEntrypoint runnerEntry
236
+ from VarAccess v , ActionsLibImport actionsLib , RunnerEntrypoint runnerEntry
158
237
where actionsLib .getAProvidedVariable ( ) = v .getVariable ( )
159
238
and getAFunctionChildExpr ( calledBy * ( runnerEntry ) ) = v
160
239
and not ( isSafeActionLibWithActionsEnvVars ( actionsLib .getName ( ) ) and runnerEntry .setsActionsEnvVars ( ) )
0 commit comments