@@ -10,13 +10,11 @@ module Argument1RoutingTest implements RoutingTestSig {
1010
1111 predicate relevantFlow ( DataFlow:: Node source , DataFlow:: Node sink , Argument arg ) {
1212 (
13- exists ( Argument1ExtraRoutingConfig cfg | cfg . hasFlow ( source , sink ) )
13+ Argument1ExtraRoutingFlow :: flow ( source , sink )
1414 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 )
2018 ) and
2119 exists ( arg )
2220 }
@@ -26,46 +24,42 @@ class ArgNumber extends int {
2624 ArgNumber ( ) { this in [ 1 .. 7 ] }
2725}
2826
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 ) {
3329 node .( DataFlow:: CfgNode ) .getNode ( ) .( NameNode ) .getId ( ) = "arg" + argNumber
3430 }
3531
36- override predicate isSource ( DataFlow:: Node node ) { this . isArgSource ( node , _) }
32+ predicate isSource ( DataFlow:: Node node ) { isArgSource ( node , _) }
3733
38- predicate isGoodSink ( DataFlow:: Node node , ArgNumber argNumber ) {
34+ additional predicate isGoodSink ( DataFlow:: Node node , ArgNumber argNumber ) {
3935 exists ( CallNode call |
4036 call .getFunction ( ) .( NameNode ) .getId ( ) = "SINK" + argNumber and
4137 node .( DataFlow:: CfgNode ) .getNode ( ) = call .getAnArg ( )
4238 )
4339 }
4440
45- predicate isBadSink ( DataFlow:: Node node , ArgNumber argNumber ) {
41+ additional predicate isBadSink ( DataFlow:: Node node , ArgNumber argNumber ) {
4642 exists ( CallNode call |
4743 call .getFunction ( ) .( NameNode ) .getId ( ) = "SINK" + argNumber + "_F" and
4844 node .( DataFlow:: CfgNode ) .getNode ( ) = call .getAnArg ( )
4945 )
5046 }
5147
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 , _) }
5549
5650 /**
5751 * We want to be able to use `arg` in a sequence of calls such as `func(kw=arg); ... ; func(arg)`.
5852 * Use-use flow lets the argument to the first call reach the sink inside the second call,
5953 * making it seem like we handle all cases even if we only handle the last one.
6054 * We make the test honest by preventing flow into source nodes.
6155 */
62- override predicate isBarrierIn ( DataFlow:: Node node ) { this . isSource ( node ) }
56+ predicate isBarrierIn ( DataFlow:: Node node ) { isSource ( node ) }
6357}
6458
65- class Argument1ExtraRoutingConfig extends DataFlow:: Configuration {
66- Argument1ExtraRoutingConfig ( ) { this = "Argument1ExtraRoutingConfig" }
59+ module ArgumentRoutingFlow = DataFlow:: Global< ArgumentRoutingConfig > ;
6760
68- override predicate isSource ( DataFlow:: Node node ) {
61+ module Argument1ExtraRoutingConfig implements DataFlow:: ConfigSig {
62+ predicate isSource ( DataFlow:: Node node ) {
6963 exists ( AssignmentDefinition def , DataFlow:: CallCfgNode call |
7064 def .getVariable ( ) = node .( DataFlow:: EssaNode ) .getVar ( ) and
7165 def .getValue ( ) = call .getNode ( ) and
@@ -74,7 +68,7 @@ class Argument1ExtraRoutingConfig extends DataFlow::Configuration {
7468 node .( DataFlow:: EssaNode ) .getVar ( ) .getName ( ) .matches ( "with\\_%" )
7569 }
7670
77- override predicate isSink ( DataFlow:: Node node ) {
71+ predicate isSink ( DataFlow:: Node node ) {
7872 exists ( CallNode call |
7973 call .getFunction ( ) .( NameNode ) .getId ( ) = "SINK1" and
8074 node .( DataFlow:: CfgNode ) .getNode ( ) = call .getAnArg ( )
@@ -87,20 +81,20 @@ class Argument1ExtraRoutingConfig extends DataFlow::Configuration {
8781 * making it seem like we handle all cases even if we only handle the last one.
8882 * We make the test honest by preventing flow into source nodes.
8983 */
90- override predicate isBarrierIn ( DataFlow:: Node node ) { this . isSource ( node ) }
84+ predicate isBarrierIn ( DataFlow:: Node node ) { isSource ( node ) }
9185}
9286
87+ module Argument1ExtraRoutingFlow = DataFlow:: Global< Argument1ExtraRoutingConfig > ;
88+
9389module RestArgumentRoutingTest implements RoutingTestSig {
9490 class Argument = ArgNumber ;
9591
9692 string flowTag ( Argument arg ) { result = "arg" + arg }
9793
9894 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
10498 arg > 1
10599 }
106100}
@@ -112,11 +106,9 @@ module BadArgumentRoutingTestSinkF implements RoutingTestSig {
112106 string flowTag ( Argument arg ) { result = "bad" + arg }
113107
114108 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 )
120112 }
121113}
122114
@@ -127,14 +119,12 @@ module BadArgumentRoutingTestWrongSink implements RoutingTestSig {
127119 string flowTag ( Argument arg ) { result = "bad" + arg }
128120
129121 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 )
138128 )
139129 }
140130}
0 commit comments