@@ -10,13 +10,11 @@ module Argument1RoutingTest implements RoutingTestSig {
10
10
11
11
predicate relevantFlow ( DataFlow:: Node source , DataFlow:: Node sink , Argument arg ) {
12
12
(
13
- exists ( Argument1ExtraRoutingConfig cfg | cfg . hasFlow ( source , sink ) )
13
+ Argument1ExtraRoutingFlow :: flow ( source , sink )
14
14
or
15
- exists ( ArgumentRoutingConfig cfg |
16
- cfg .hasFlow ( source , sink ) and
17
- cfg .isArgSource ( source , 1 ) and
18
- cfg .isGoodSink ( sink , 1 )
19
- )
15
+ ArgumentRoutingFlow:: flow ( source , sink ) and
16
+ ArgumentRoutingConfig:: isArgSource ( source , 1 ) and
17
+ ArgumentRoutingConfig:: isGoodSink ( sink , 1 )
20
18
) and
21
19
exists ( arg )
22
20
}
@@ -26,46 +24,42 @@ class ArgNumber extends int {
26
24
ArgNumber ( ) { this in [ 1 .. 7 ] }
27
25
}
28
26
29
- class ArgumentRoutingConfig extends DataFlow:: Configuration {
30
- ArgumentRoutingConfig ( ) { this = "ArgumentRoutingConfig" }
31
-
32
- predicate isArgSource ( DataFlow:: Node node , ArgNumber argNumber ) {
27
+ module ArgumentRoutingConfig implements DataFlow:: ConfigSig {
28
+ additional predicate isArgSource ( DataFlow:: Node node , ArgNumber argNumber ) {
33
29
node .( DataFlow:: CfgNode ) .getNode ( ) .( NameNode ) .getId ( ) = "arg" + argNumber
34
30
}
35
31
36
- override predicate isSource ( DataFlow:: Node node ) { this . isArgSource ( node , _) }
32
+ predicate isSource ( DataFlow:: Node node ) { isArgSource ( node , _) }
37
33
38
- predicate isGoodSink ( DataFlow:: Node node , ArgNumber argNumber ) {
34
+ additional predicate isGoodSink ( DataFlow:: Node node , ArgNumber argNumber ) {
39
35
exists ( CallNode call |
40
36
call .getFunction ( ) .( NameNode ) .getId ( ) = "SINK" + argNumber and
41
37
node .( DataFlow:: CfgNode ) .getNode ( ) = call .getAnArg ( )
42
38
)
43
39
}
44
40
45
- predicate isBadSink ( DataFlow:: Node node , ArgNumber argNumber ) {
41
+ additional predicate isBadSink ( DataFlow:: Node node , ArgNumber argNumber ) {
46
42
exists ( CallNode call |
47
43
call .getFunction ( ) .( NameNode ) .getId ( ) = "SINK" + argNumber + "_F" and
48
44
node .( DataFlow:: CfgNode ) .getNode ( ) = call .getAnArg ( )
49
45
)
50
46
}
51
47
52
- override predicate isSink ( DataFlow:: Node node ) {
53
- this .isGoodSink ( node , _) or this .isBadSink ( node , _)
54
- }
48
+ predicate isSink ( DataFlow:: Node node ) { isGoodSink ( node , _) or isBadSink ( node , _) }
55
49
56
50
/**
57
51
* We want to be able to use `arg` in a sequence of calls such as `func(kw=arg); ... ; func(arg)`.
58
52
* Use-use flow lets the argument to the first call reach the sink inside the second call,
59
53
* making it seem like we handle all cases even if we only handle the last one.
60
54
* We make the test honest by preventing flow into source nodes.
61
55
*/
62
- override predicate isBarrierIn ( DataFlow:: Node node ) { this . isSource ( node ) }
56
+ predicate isBarrierIn ( DataFlow:: Node node ) { isSource ( node ) }
63
57
}
64
58
65
- class Argument1ExtraRoutingConfig extends DataFlow:: Configuration {
66
- Argument1ExtraRoutingConfig ( ) { this = "Argument1ExtraRoutingConfig" }
59
+ module ArgumentRoutingFlow = DataFlow:: Global< ArgumentRoutingConfig > ;
67
60
68
- override predicate isSource ( DataFlow:: Node node ) {
61
+ module Argument1ExtraRoutingConfig implements DataFlow:: ConfigSig {
62
+ predicate isSource ( DataFlow:: Node node ) {
69
63
exists ( AssignmentDefinition def , DataFlow:: CallCfgNode call |
70
64
def .getVariable ( ) = node .( DataFlow:: EssaNode ) .getVar ( ) and
71
65
def .getValue ( ) = call .getNode ( ) and
@@ -74,7 +68,7 @@ class Argument1ExtraRoutingConfig extends DataFlow::Configuration {
74
68
node .( DataFlow:: EssaNode ) .getVar ( ) .getName ( ) .matches ( "with\\_%" )
75
69
}
76
70
77
- override predicate isSink ( DataFlow:: Node node ) {
71
+ predicate isSink ( DataFlow:: Node node ) {
78
72
exists ( CallNode call |
79
73
call .getFunction ( ) .( NameNode ) .getId ( ) = "SINK1" and
80
74
node .( DataFlow:: CfgNode ) .getNode ( ) = call .getAnArg ( )
@@ -87,20 +81,20 @@ class Argument1ExtraRoutingConfig extends DataFlow::Configuration {
87
81
* making it seem like we handle all cases even if we only handle the last one.
88
82
* We make the test honest by preventing flow into source nodes.
89
83
*/
90
- override predicate isBarrierIn ( DataFlow:: Node node ) { this . isSource ( node ) }
84
+ predicate isBarrierIn ( DataFlow:: Node node ) { isSource ( node ) }
91
85
}
92
86
87
+ module Argument1ExtraRoutingFlow = DataFlow:: Global< Argument1ExtraRoutingConfig > ;
88
+
93
89
module RestArgumentRoutingTest implements RoutingTestSig {
94
90
class Argument = ArgNumber ;
95
91
96
92
string flowTag ( Argument arg ) { result = "arg" + arg }
97
93
98
94
predicate relevantFlow ( DataFlow:: Node source , DataFlow:: Node sink , Argument arg ) {
99
- exists ( ArgumentRoutingConfig cfg |
100
- cfg .hasFlow ( source , sink ) and
101
- cfg .isArgSource ( source , arg ) and
102
- cfg .isGoodSink ( sink , arg )
103
- ) and
95
+ ArgumentRoutingFlow:: flow ( source , sink ) and
96
+ ArgumentRoutingConfig:: isArgSource ( source , arg ) and
97
+ ArgumentRoutingConfig:: isGoodSink ( sink , arg ) and
104
98
arg > 1
105
99
}
106
100
}
@@ -112,11 +106,9 @@ module BadArgumentRoutingTestSinkF implements RoutingTestSig {
112
106
string flowTag ( Argument arg ) { result = "bad" + arg }
113
107
114
108
predicate relevantFlow ( DataFlow:: Node source , DataFlow:: Node sink , Argument arg ) {
115
- exists ( ArgumentRoutingConfig cfg |
116
- cfg .hasFlow ( source , sink ) and
117
- cfg .isArgSource ( source , arg ) and
118
- cfg .isBadSink ( sink , arg )
119
- )
109
+ ArgumentRoutingFlow:: flow ( source , sink ) and
110
+ ArgumentRoutingConfig:: isArgSource ( source , arg ) and
111
+ ArgumentRoutingConfig:: isBadSink ( sink , arg )
120
112
}
121
113
}
122
114
@@ -127,14 +119,12 @@ module BadArgumentRoutingTestWrongSink implements RoutingTestSig {
127
119
string flowTag ( Argument arg ) { result = "bad" + arg }
128
120
129
121
predicate relevantFlow ( DataFlow:: Node source , DataFlow:: Node sink , Argument arg ) {
130
- exists ( ArgumentRoutingConfig cfg |
131
- cfg .hasFlow ( source , sink ) and
132
- cfg .isArgSource ( source , any ( ArgNumber i | not i = arg ) ) and
133
- (
134
- cfg .isGoodSink ( sink , arg )
135
- or
136
- cfg .isBadSink ( sink , arg )
137
- )
122
+ ArgumentRoutingFlow:: flow ( source , sink ) and
123
+ ArgumentRoutingConfig:: isArgSource ( source , any ( ArgNumber i | not i = arg ) ) and
124
+ (
125
+ ArgumentRoutingConfig:: isGoodSink ( sink , arg )
126
+ or
127
+ ArgumentRoutingConfig:: isBadSink ( sink , arg )
138
128
)
139
129
}
140
130
}
0 commit comments