@@ -57,12 +57,40 @@ class Untainted extends TaintType, TExactValue { }
5757/** A taint type where the data is tainted. */
5858class Tainted extends TaintType , TTaintedValue { }
5959
60+ private predicate localFlowPhiInput ( DataFlowNode input , Ssa:: PhiNode phi ) {
61+ exists ( Ssa:: Definition def , BasicBlock bb , int i | phi .hasLastInputRef ( def , bb , i ) |
62+ def .definesAt ( _, bb , i ) and
63+ input = def .getVariableUpdate ( ) .getSource ( )
64+ or
65+ input =
66+ any ( ReadAccess ra |
67+ bb .getNode ( i ) = ra and
68+ ra .getTarget ( ) = def .getSourceVariable ( )
69+ )
70+ )
71+ or
72+ exists ( Ssa:: PhiNode mid , BasicBlock bb , int i |
73+ localFlowPhiInput ( input , mid ) and
74+ phi .hasLastInputRef ( mid , bb , i ) and
75+ mid .definesAt ( _, bb , i )
76+ )
77+ }
78+
6079private predicate localExactStep ( DataFlowNode src , DataFlowNode sink ) {
6180 src = sink .( Opcodes:: Dup ) .getAnOperand ( )
6281 or
63- defUse ( _, src , sink )
82+ exists ( Ssa:: Definition def , VariableUpdate vu |
83+ vu = def .getVariableUpdate ( ) and
84+ src = vu .getSource ( ) and
85+ sink = def .getAFirstRead ( )
86+ )
87+ or
88+ any ( Ssa:: Definition def ) .hasAdjacentReads ( src , sink )
6489 or
65- src = sink .( ParameterReadAccess ) .getTarget ( )
90+ exists ( Ssa:: PhiNode phi |
91+ localFlowPhiInput ( src , phi ) and
92+ sink = phi .getAFirstRead ( )
93+ )
6694 or
6795 src = sink .( Conversion ) .getExpr ( )
6896 or
@@ -73,12 +101,6 @@ private predicate localExactStep(DataFlowNode src, DataFlowNode sink) {
73101 src = sink .( Return ) .getExpr ( )
74102 or
75103 src = sink .( ConditionalBranch ) .getAnOperand ( )
76- or
77- src = sink .( MethodParameter ) .getAWrite ( )
78- or
79- exists ( VariableUpdate update |
80- update .getVariable ( ) .( Parameter ) = sink and src = update .getSource ( )
81- )
82104}
83105
84106private predicate localTaintStep ( DataFlowNode src , DataFlowNode sink ) {
@@ -87,8 +109,7 @@ private predicate localTaintStep(DataFlowNode src, DataFlowNode sink) {
87109 src = sink .( UnaryBitwiseOperation ) .getOperand ( )
88110}
89111
90- cached
91- module DefUse {
112+ deprecated module DefUse {
92113 /**
93114 * A classification of variable references into reads and writes.
94115 */
@@ -189,7 +210,7 @@ module DefUse {
189210
190211 /** Holds if the variable update `vu` can be used at the read `use`. */
191212 cached
192- predicate variableUpdateUse ( StackVariable target , VariableUpdate vu , ReadAccess use ) {
213+ deprecated predicate variableUpdateUse ( StackVariable target , VariableUpdate vu , ReadAccess use ) {
193214 defReachesReadWithinBlock ( target , vu , use )
194215 or
195216 exists ( BasicBlock bb , int i |
@@ -202,23 +223,40 @@ module DefUse {
202223
203224 /** Holds if the update `def` can be used at the read `use`. */
204225 cached
205- predicate defUse ( StackVariable target , Expr def , ReadAccess use ) {
226+ deprecated predicate defUse ( StackVariable target , Expr def , ReadAccess use ) {
206227 exists ( VariableUpdate vu | def = vu .getSource ( ) | variableUpdateUse ( target , vu , use ) )
207228 }
208229}
209230
210- private import DefUse
211-
212- abstract library class VariableUpdate extends Instruction {
213- abstract Expr getSource ( ) ;
231+ /** A node that updates a variable. */
232+ abstract class VariableUpdate extends DataFlowNode {
233+ /** Gets the value assigned, if any. */
234+ abstract DataFlowNode getSource ( ) ;
214235
236+ /** Gets the variable that is updated. */
215237 abstract Variable getVariable ( ) ;
238+
239+ /** Holds if this variable update happens at index `i` in basic block `bb`. */
240+ abstract predicate updatesAt ( BasicBlock bb , int i ) ;
241+ }
242+
243+ private class MethodParameterDef extends VariableUpdate , MethodParameter {
244+ override MethodParameter getSource ( ) { result = this }
245+
246+ override MethodParameter getVariable ( ) { result = this }
247+
248+ override predicate updatesAt ( BasicBlock bb , int i ) {
249+ bb .( EntryBasicBlock ) .getANode ( ) .getImplementation ( ) .getMethod ( ) = this .getMethod ( ) and
250+ i = - 1
251+ }
216252}
217253
218254private class VariableWrite extends VariableUpdate , WriteAccess {
219- override Expr getSource ( ) { result = getExpr ( ) }
255+ override Expr getSource ( ) { result = this . getExpr ( ) }
220256
221- override Variable getVariable ( ) { result = getTarget ( ) }
257+ override Variable getVariable ( ) { result = this .getTarget ( ) }
258+
259+ override predicate updatesAt ( BasicBlock bb , int i ) { this = bb .getNode ( i ) }
222260}
223261
224262private class MethodOutOrRefTarget extends VariableUpdate , Call {
@@ -230,5 +268,7 @@ private class MethodOutOrRefTarget extends VariableUpdate, Call {
230268 result = this .getRawArgument ( parameterIndex ) .( ReadAccess ) .getTarget ( )
231269 }
232270
233- override Expr getSource ( ) { result = this }
271+ override Expr getSource ( ) { none ( ) }
272+
273+ override predicate updatesAt ( BasicBlock bb , int i ) { this = bb .getNode ( i ) }
234274}
0 commit comments