@@ -90,17 +90,96 @@ class RunnerEntrypoint extends Function {
9090 }
9191}
9292
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+
93172/**
94173 * A check of whether we are in actions mode or runner mode.
95174 */
96- class ModeGuard extends IfStmt {
175+ class ModeGuard extends ActionsGuard {
97176 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 ( )
100179 }
101180
102- string getOperand ( ) {
103- result = getCondition ( ) .( EqualityTest ) .getAnOperand ( ) . ( StringLiteral ) . getValue ( )
181+ ModeAccess getOperand ( ) {
182+ result = getCondition ( ) .( EqualityTest ) .getAnOperand ( )
104183 }
105184
106185 predicate isPositive ( ) {
@@ -111,19 +190,19 @@ class ModeGuard extends IfStmt {
111190 * Get the then or else block that is the "actions" path.
112191 */
113192 Stmt getActionsBlock ( ) {
114- ( getOperand ( ) = "actions" and isPositive ( ) and result = getThen ( ) )
193+ ( getOperand ( ) . isActions ( ) and isPositive ( ) and result = getThen ( ) )
115194 or
116- ( getOperand ( ) = "runner" and not isPositive ( ) and result = getThen ( ) )
195+ ( getOperand ( ) . isRunner ( ) and not isPositive ( ) and result = getThen ( ) )
117196 or
118- ( getOperand ( ) = "actions" and not isPositive ( ) and result = getElse ( ) )
197+ ( getOperand ( ) . isActions ( ) and not isPositive ( ) and result = getElse ( ) )
119198 or
120- ( getOperand ( ) = "runner" and isPositive ( ) and result = getElse ( ) )
199+ ( getOperand ( ) . isRunner ( ) and isPositive ( ) and result = getElse ( ) )
121200 }
122201
123202 /**
124203 * Get an expr that is only executed on actions
125204 */
126- Expr getAnActionsExpr ( ) {
205+ override Expr getAnActionsExpr ( ) {
127206 getActionsBlock ( ) .getAChildStmt * ( ) .getAChildExpr * ( ) = result
128207 }
129208}
@@ -133,7 +212,7 @@ class ModeGuard extends IfStmt {
133212 * and is not only called on actions.
134213 */
135214Expr getAFunctionChildExpr ( Function f ) {
136- not exists ( ModeGuard guard | guard .getAnActionsExpr ( ) = result ) and
215+ not exists ( ActionsGuard guard | guard .getAnActionsExpr ( ) = result ) and
137216 result .getContainer ( ) = f
138217}
139218
@@ -145,16 +224,16 @@ Function calledBy(Function f) {
145224 exists ( InvokeExpr invokeExpr |
146225 invokeExpr = getAFunctionChildExpr ( f ) and
147226 invokeExpr .getResolvedCallee ( ) = result and
148- not exists ( ModeGuard guard | guard .getAnActionsExpr ( ) = invokeExpr )
227+ not exists ( ActionsGuard guard | guard .getAnActionsExpr ( ) = invokeExpr )
149228 )
150229 or
151230 // Assume outer function causes inner function to be called
152231 ( result instanceof Expr and
153232 result .getEnclosingContainer ( ) = f and
154- not exists ( ModeGuard guard | guard .getAnActionsExpr ( ) = result ) )
233+ not exists ( ActionsGuard guard | guard .getAnActionsExpr ( ) = result ) )
155234}
156235
157- from VarAccess v , ActionsLibImport actionsLib , RunnerEntrypoint runnerEntry
236+ from VarAccess v , ActionsLibImport actionsLib , RunnerEntrypoint runnerEntry
158237where actionsLib .getAProvidedVariable ( ) = v .getVariable ( )
159238 and getAFunctionChildExpr ( calledBy * ( runnerEntry ) ) = v
160239 and not ( isSafeActionLibWithActionsEnvVars ( actionsLib .getName ( ) ) and runnerEntry .setsActionsEnvVars ( ) )
0 commit comments