5
5
*/
6
6
7
7
private import cpp
8
- import semmle.code.cpp.ir.dataflow.DataFlow
9
8
private import semmle.code.cpp.ir.IR
10
9
11
10
/**
@@ -25,18 +24,18 @@ abstract class MustFlowConfiguration extends string {
25
24
/**
26
25
* Holds if `source` is a relevant data flow source.
27
26
*/
28
- abstract predicate isSource ( DataFlow :: Node source ) ;
27
+ abstract predicate isSource ( Instruction source ) ;
29
28
30
29
/**
31
30
* Holds if `sink` is a relevant data flow sink.
32
31
*/
33
- abstract predicate isSink ( DataFlow :: Node sink ) ;
32
+ abstract predicate isSink ( Operand sink ) ;
34
33
35
34
/**
36
35
* Holds if the additional flow step from `node1` to `node2` must be taken
37
36
* into account in the analysis.
38
37
*/
39
- predicate isAdditionalFlowStep ( DataFlow :: Node node1 , DataFlow :: Node node2 ) { none ( ) }
38
+ predicate isAdditionalFlowStep ( Operand node1 , Instruction node2 ) { none ( ) }
40
39
41
40
/** Holds if this configuration allows flow from arguments to parameters. */
42
41
predicate allowInterproceduralFlow ( ) { any ( ) }
@@ -48,30 +47,30 @@ abstract class MustFlowConfiguration extends string {
48
47
* included in the module `PathGraph`.
49
48
*/
50
49
final predicate hasFlowPath ( MustFlowPathNode source , MustFlowPathSink sink ) {
51
- this .isSource ( source .getNode ( ) ) and
50
+ this .isSource ( source .getInstruction ( ) ) and
52
51
source .getASuccessor + ( ) = sink
53
52
}
54
53
}
55
54
56
55
/** Holds if `node` flows from a source. */
57
56
pragma [ nomagic]
58
- private predicate flowsFromSource ( DataFlow :: Node node , MustFlowConfiguration config ) {
57
+ private predicate flowsFromSource ( Instruction node , MustFlowConfiguration config ) {
59
58
config .isSource ( node )
60
59
or
61
- exists ( DataFlow :: Node mid |
60
+ exists ( Instruction mid |
62
61
step ( mid , node , config ) and
63
62
flowsFromSource ( mid , pragma [ only_bind_into ] ( config ) )
64
63
)
65
64
}
66
65
67
66
/** Holds if `node` flows to a sink. */
68
67
pragma [ nomagic]
69
- private predicate flowsToSink ( DataFlow :: Node node , MustFlowConfiguration config ) {
68
+ private predicate flowsToSink ( Instruction node , MustFlowConfiguration config ) {
70
69
flowsFromSource ( node , pragma [ only_bind_into ] ( config ) ) and
71
70
(
72
- config .isSink ( node )
71
+ config .isSink ( node . getAUse ( ) )
73
72
or
74
- exists ( DataFlow :: Node mid |
73
+ exists ( Instruction mid |
75
74
step ( node , mid , config ) and
76
75
flowsToSink ( mid , pragma [ only_bind_into ] ( config ) )
77
76
)
@@ -198,12 +197,13 @@ private module Cached {
198
197
}
199
198
200
199
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
+ )
205
205
or
206
- operandToInstructionStep ( nodeFrom . asOperand ( ) , nodeTo . asInstruction ( ) )
206
+ flowThroughCallable ( nodeFrom , nodeTo )
207
207
}
208
208
}
209
209
@@ -213,12 +213,12 @@ private module Cached {
213
213
* way around.
214
214
*/
215
215
pragma [ 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 ( )
218
218
}
219
219
220
220
/** 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 ) {
222
222
exists ( config ) and
223
223
Cached:: step ( pragma [ only_bind_into ] ( nodeFrom ) , pragma [ only_bind_into ] ( nodeTo ) ) and
224
224
(
@@ -227,45 +227,45 @@ private predicate step(DataFlow::Node nodeFrom, DataFlow::Node nodeTo, MustFlowC
227
227
getEnclosingCallable ( nodeFrom ) = getEnclosingCallable ( nodeTo )
228
228
)
229
229
or
230
- config .isAdditionalFlowStep ( nodeFrom , nodeTo )
230
+ config .isAdditionalFlowStep ( nodeFrom . getAUse ( ) , nodeTo )
231
231
}
232
232
233
233
private newtype TLocalPathNode =
234
- MkLocalPathNode ( DataFlow :: Node n , MustFlowConfiguration config ) {
234
+ MkLocalPathNode ( Instruction n , MustFlowConfiguration config ) {
235
235
flowsToSink ( n , config ) and
236
236
(
237
237
config .isSource ( n )
238
238
or
239
- exists ( MustFlowPathNode mid | step ( mid .getNode ( ) , n , config ) )
239
+ exists ( MustFlowPathNode mid | step ( mid .getInstruction ( ) , n , config ) )
240
240
)
241
241
}
242
242
243
243
/** A `Node` that is in a path from a source to a sink. */
244
244
class MustFlowPathNode extends TLocalPathNode {
245
- DataFlow :: Node n ;
245
+ Instruction n ;
246
246
247
247
MustFlowPathNode ( ) { this = MkLocalPathNode ( n , _) }
248
248
249
249
/** Gets the underlying node. */
250
- DataFlow :: Node getNode ( ) { result = n }
250
+ Instruction getInstruction ( ) { result = n }
251
251
252
252
/** Gets a textual representation of this node. */
253
- string toString ( ) { result = n .toString ( ) }
253
+ string toString ( ) { result = n .getAst ( ) . toString ( ) }
254
254
255
255
/** Gets the location of this element. */
256
256
Location getLocation ( ) { result = n .getLocation ( ) }
257
257
258
258
/** Gets a successor node, if any. */
259
259
MustFlowPathNode getASuccessor ( ) {
260
- step ( this .getNode ( ) , result .getNode ( ) , this .getConfiguration ( ) )
260
+ step ( this .getInstruction ( ) , result .getInstruction ( ) , this .getConfiguration ( ) )
261
261
}
262
262
263
263
/** Gets the associated configuration. */
264
264
MustFlowConfiguration getConfiguration ( ) { this = MkLocalPathNode ( _, result ) }
265
265
}
266
266
267
267
private class MustFlowPathSink extends MustFlowPathNode {
268
- MustFlowPathSink ( ) { this .getConfiguration ( ) .isSink ( this .getNode ( ) ) }
268
+ MustFlowPathSink ( ) { this .getConfiguration ( ) .isSink ( this .getInstruction ( ) . getAUse ( ) ) }
269
269
}
270
270
271
271
/**
0 commit comments