55 */
66
77private import cpp
8- import semmle.code.cpp.ir.dataflow.DataFlow
98private import semmle.code.cpp.ir.IR
109
1110/**
@@ -25,18 +24,18 @@ abstract class MustFlowConfiguration extends string {
2524 /**
2625 * Holds if `source` is a relevant data flow source.
2726 */
28- abstract predicate isSource ( DataFlow :: Node source ) ;
27+ abstract predicate isSource ( Instruction source ) ;
2928
3029 /**
3130 * Holds if `sink` is a relevant data flow sink.
3231 */
33- abstract predicate isSink ( DataFlow :: Node sink ) ;
32+ abstract predicate isSink ( Operand sink ) ;
3433
3534 /**
3635 * Holds if the additional flow step from `node1` to `node2` must be taken
3736 * into account in the analysis.
3837 */
39- predicate isAdditionalFlowStep ( DataFlow :: Node node1 , DataFlow :: Node node2 ) { none ( ) }
38+ predicate isAdditionalFlowStep ( Operand node1 , Instruction node2 ) { none ( ) }
4039
4140 /** Holds if this configuration allows flow from arguments to parameters. */
4241 predicate allowInterproceduralFlow ( ) { any ( ) }
@@ -48,30 +47,30 @@ abstract class MustFlowConfiguration extends string {
4847 * included in the module `PathGraph`.
4948 */
5049 final predicate hasFlowPath ( MustFlowPathNode source , MustFlowPathSink sink ) {
51- this .isSource ( source .getNode ( ) ) and
50+ this .isSource ( source .getInstruction ( ) ) and
5251 source .getASuccessor + ( ) = sink
5352 }
5453}
5554
5655/** Holds if `node` flows from a source. */
5756pragma [ nomagic]
58- private predicate flowsFromSource ( DataFlow :: Node node , MustFlowConfiguration config ) {
57+ private predicate flowsFromSource ( Instruction node , MustFlowConfiguration config ) {
5958 config .isSource ( node )
6059 or
61- exists ( DataFlow :: Node mid |
60+ exists ( Instruction mid |
6261 step ( mid , node , config ) and
6362 flowsFromSource ( mid , pragma [ only_bind_into ] ( config ) )
6463 )
6564}
6665
6766/** Holds if `node` flows to a sink. */
6867pragma [ nomagic]
69- private predicate flowsToSink ( DataFlow :: Node node , MustFlowConfiguration config ) {
68+ private predicate flowsToSink ( Instruction node , MustFlowConfiguration config ) {
7069 flowsFromSource ( node , pragma [ only_bind_into ] ( config ) ) and
7170 (
72- config .isSink ( node )
71+ config .isSink ( node . getAUse ( ) )
7372 or
74- exists ( DataFlow :: Node mid |
73+ exists ( Instruction mid |
7574 step ( node , mid , config ) and
7675 flowsToSink ( mid , pragma [ only_bind_into ] ( config ) )
7776 )
@@ -198,12 +197,13 @@ private module Cached {
198197 }
199198
200199 cached
201- predicate step ( DataFlow:: Node nodeFrom , DataFlow:: Node nodeTo ) {
202- instructionToOperandStep ( nodeFrom .asInstruction ( ) , nodeTo .asOperand ( ) )
203- or
204- flowThroughCallable ( nodeFrom .asInstruction ( ) , nodeTo .asInstruction ( ) )
200+ predicate step ( Instruction nodeFrom , Instruction nodeTo ) {
201+ exists ( Operand mid |
202+ instructionToOperandStep ( nodeFrom , mid ) and
203+ operandToInstructionStep ( mid , nodeTo )
204+ )
205205 or
206- operandToInstructionStep ( nodeFrom . asOperand ( ) , nodeTo . asInstruction ( ) )
206+ flowThroughCallable ( nodeFrom , nodeTo )
207207 }
208208}
209209
@@ -213,12 +213,12 @@ private module Cached {
213213 * way around.
214214 */
215215pragma [ inline]
216- private Declaration getEnclosingCallable ( DataFlow :: Node n ) {
217- pragma [ only_bind_into ] ( result ) = pragma [ only_bind_out ] ( n ) .getEnclosingCallable ( )
216+ private IRFunction getEnclosingCallable ( Instruction n ) {
217+ pragma [ only_bind_into ] ( result ) = pragma [ only_bind_out ] ( n ) .getEnclosingIRFunction ( )
218218}
219219
220220/** Holds if `nodeFrom` flows to `nodeTo`. */
221- private predicate step ( DataFlow :: Node nodeFrom , DataFlow :: Node nodeTo , MustFlowConfiguration config ) {
221+ private predicate step ( Instruction nodeFrom , Instruction nodeTo , MustFlowConfiguration config ) {
222222 exists ( config ) and
223223 Cached:: step ( pragma [ only_bind_into ] ( nodeFrom ) , pragma [ only_bind_into ] ( nodeTo ) ) and
224224 (
@@ -227,45 +227,45 @@ private predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo, MustFlowC
227227 getEnclosingCallable ( nodeFrom ) = getEnclosingCallable ( nodeTo )
228228 )
229229 or
230- config .isAdditionalFlowStep ( nodeFrom , nodeTo )
230+ config .isAdditionalFlowStep ( nodeFrom . getAUse ( ) , nodeTo )
231231}
232232
233233private newtype TLocalPathNode =
234- MkLocalPathNode ( DataFlow :: Node n , MustFlowConfiguration config ) {
234+ MkLocalPathNode ( Instruction n , MustFlowConfiguration config ) {
235235 flowsToSink ( n , config ) and
236236 (
237237 config .isSource ( n )
238238 or
239- exists ( MustFlowPathNode mid | step ( mid .getNode ( ) , n , config ) )
239+ exists ( MustFlowPathNode mid | step ( mid .getInstruction ( ) , n , config ) )
240240 )
241241 }
242242
243243/** A `Node` that is in a path from a source to a sink. */
244244class MustFlowPathNode extends TLocalPathNode {
245- DataFlow :: Node n ;
245+ Instruction n ;
246246
247247 MustFlowPathNode ( ) { this = MkLocalPathNode ( n , _) }
248248
249249 /** Gets the underlying node. */
250- DataFlow :: Node getNode ( ) { result = n }
250+ Instruction getInstruction ( ) { result = n }
251251
252252 /** Gets a textual representation of this node. */
253- string toString ( ) { result = n .toString ( ) }
253+ string toString ( ) { result = n .getAst ( ) . toString ( ) }
254254
255255 /** Gets the location of this element. */
256256 Location getLocation ( ) { result = n .getLocation ( ) }
257257
258258 /** Gets a successor node, if any. */
259259 MustFlowPathNode getASuccessor ( ) {
260- step ( this .getNode ( ) , result .getNode ( ) , this .getConfiguration ( ) )
260+ step ( this .getInstruction ( ) , result .getInstruction ( ) , this .getConfiguration ( ) )
261261 }
262262
263263 /** Gets the associated configuration. */
264264 MustFlowConfiguration getConfiguration ( ) { this = MkLocalPathNode ( _, result ) }
265265}
266266
267267private class MustFlowPathSink extends MustFlowPathNode {
268- MustFlowPathSink ( ) { this .getConfiguration ( ) .isSink ( this .getNode ( ) ) }
268+ MustFlowPathSink ( ) { this .getConfiguration ( ) .isSink ( this .getInstruction ( ) . getAUse ( ) ) }
269269}
270270
271271/**
0 commit comments