16
16
import java
17
17
import semmle.code.java.dataflow.DataFlow
18
18
import ArithmeticCommon
19
- import DataFlow:: PathGraph
20
19
21
20
abstract class ExtremeValueField extends Field {
22
21
ExtremeValueField ( ) { this .getType ( ) instanceof IntegralType }
@@ -34,51 +33,56 @@ class ExtremeSource extends VarAccess {
34
33
ExtremeSource ( ) { this .getVariable ( ) instanceof ExtremeValueField }
35
34
}
36
35
37
- class MaxValueFlowConfig extends DataFlow:: Configuration {
38
- MaxValueFlowConfig ( ) { this = "MaxValueFlowConfig" }
39
-
40
- override predicate isSource ( DataFlow:: Node source ) {
36
+ private module MaxValueFlowConfig implements DataFlow:: ConfigSig {
37
+ predicate isSource ( DataFlow:: Node source ) {
41
38
source .asExpr ( ) .( ExtremeSource ) .getVariable ( ) instanceof MaxValueField
42
39
}
43
40
44
- override predicate isSink ( DataFlow:: Node sink ) { overflowSink ( _, sink .asExpr ( ) ) }
41
+ predicate isSink ( DataFlow:: Node sink ) { overflowSink ( _, sink .asExpr ( ) ) }
45
42
46
- override predicate isBarrierIn ( DataFlow:: Node n ) { this . isSource ( n ) }
43
+ predicate isBarrierIn ( DataFlow:: Node n ) { isSource ( n ) }
47
44
48
- override predicate isBarrier ( DataFlow:: Node n ) { overflowBarrier ( n ) }
45
+ predicate isBarrier ( DataFlow:: Node n ) { overflowBarrier ( n ) }
49
46
}
50
47
51
- class MinValueFlowConfig extends DataFlow:: Configuration {
52
- MinValueFlowConfig ( ) { this = "MinValueFlowConfig" }
48
+ module MaxValueFlow = DataFlow:: Make< MaxValueFlowConfig > ;
53
49
54
- override predicate isSource ( DataFlow:: Node source ) {
50
+ private module MinValueFlowConfig implements DataFlow:: ConfigSig {
51
+ predicate isSource ( DataFlow:: Node source ) {
55
52
source .asExpr ( ) .( ExtremeSource ) .getVariable ( ) instanceof MinValueField
56
53
}
57
54
58
- override predicate isSink ( DataFlow:: Node sink ) { underflowSink ( _, sink .asExpr ( ) ) }
55
+ predicate isSink ( DataFlow:: Node sink ) { underflowSink ( _, sink .asExpr ( ) ) }
59
56
60
- override predicate isBarrierIn ( DataFlow:: Node n ) { this . isSource ( n ) }
57
+ predicate isBarrierIn ( DataFlow:: Node n ) { isSource ( n ) }
61
58
62
- override predicate isBarrier ( DataFlow:: Node n ) { underflowBarrier ( n ) }
59
+ predicate isBarrier ( DataFlow:: Node n ) { underflowBarrier ( n ) }
63
60
}
64
61
62
+ module MinValueFlow = DataFlow:: Make< MinValueFlowConfig > ;
63
+
64
+ module Flow =
65
+ DataFlow:: MergePathGraph< MaxValueFlow:: PathNode , MinValueFlow:: PathNode , MaxValueFlow:: PathGraph , MinValueFlow:: PathGraph > ;
66
+
67
+ import Flow:: PathGraph
68
+
65
69
predicate query (
66
- DataFlow :: PathNode source , DataFlow :: PathNode sink , ArithExpr exp , string effect , Type srctyp
70
+ Flow :: PathNode source , Flow :: PathNode sink , ArithExpr exp , string effect , Type srctyp
67
71
) {
68
72
(
69
- any ( MaxValueFlowConfig c ) . hasFlowPath ( source , sink ) and
73
+ MaxValueFlow :: hasFlowPath ( source . asPathNode1 ( ) , sink . asPathNode1 ( ) ) and
70
74
overflowSink ( exp , sink .getNode ( ) .asExpr ( ) ) and
71
75
effect = "overflow"
72
76
or
73
- any ( MinValueFlowConfig c ) . hasFlowPath ( source , sink ) and
77
+ MinValueFlow :: hasFlowPath ( source . asPathNode2 ( ) , sink . asPathNode2 ( ) ) and
74
78
underflowSink ( exp , sink .getNode ( ) .asExpr ( ) ) and
75
79
effect = "underflow"
76
80
) and
77
81
srctyp = source .getNode ( ) .asExpr ( ) .getType ( )
78
82
}
79
83
80
84
from
81
- DataFlow :: PathNode source , DataFlow :: PathNode sink , ArithExpr exp , Variable v , ExtremeSource s ,
85
+ Flow :: PathNode source , Flow :: PathNode sink , ArithExpr exp , Variable v , ExtremeSource s ,
82
86
string effect , Type srctyp
83
87
where
84
88
query ( source , sink , exp , effect , srctyp ) and
0 commit comments