1616import java
1717import semmle.code.java.dataflow.DataFlow
1818import ArithmeticCommon
19- import DataFlow:: PathGraph
2019
2120abstract class ExtremeValueField extends Field {
2221 ExtremeValueField ( ) { this .getType ( ) instanceof IntegralType }
@@ -34,51 +33,56 @@ class ExtremeSource extends VarAccess {
3433 ExtremeSource ( ) { this .getVariable ( ) instanceof ExtremeValueField }
3534}
3635
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 ) {
4138 source .asExpr ( ) .( ExtremeSource ) .getVariable ( ) instanceof MaxValueField
4239 }
4340
44- override predicate isSink ( DataFlow:: Node sink ) { overflowSink ( _, sink .asExpr ( ) ) }
41+ predicate isSink ( DataFlow:: Node sink ) { overflowSink ( _, sink .asExpr ( ) ) }
4542
46- override predicate isBarrierIn ( DataFlow:: Node n ) { this . isSource ( n ) }
43+ predicate isBarrierIn ( DataFlow:: Node n ) { isSource ( n ) }
4744
48- override predicate isBarrier ( DataFlow:: Node n ) { overflowBarrier ( n ) }
45+ predicate isBarrier ( DataFlow:: Node n ) { overflowBarrier ( n ) }
4946}
5047
51- class MinValueFlowConfig extends DataFlow:: Configuration {
52- MinValueFlowConfig ( ) { this = "MinValueFlowConfig" }
48+ module MaxValueFlow = DataFlow:: Make< MaxValueFlowConfig > ;
5349
54- override predicate isSource ( DataFlow:: Node source ) {
50+ private module MinValueFlowConfig implements DataFlow:: ConfigSig {
51+ predicate isSource ( DataFlow:: Node source ) {
5552 source .asExpr ( ) .( ExtremeSource ) .getVariable ( ) instanceof MinValueField
5653 }
5754
58- override predicate isSink ( DataFlow:: Node sink ) { underflowSink ( _, sink .asExpr ( ) ) }
55+ predicate isSink ( DataFlow:: Node sink ) { underflowSink ( _, sink .asExpr ( ) ) }
5956
60- override predicate isBarrierIn ( DataFlow:: Node n ) { this . isSource ( n ) }
57+ predicate isBarrierIn ( DataFlow:: Node n ) { isSource ( n ) }
6158
62- override predicate isBarrier ( DataFlow:: Node n ) { underflowBarrier ( n ) }
59+ predicate isBarrier ( DataFlow:: Node n ) { underflowBarrier ( n ) }
6360}
6461
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+
6569predicate 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
6771) {
6872 (
69- any ( MaxValueFlowConfig c ) . hasFlowPath ( source , sink ) and
73+ MaxValueFlow :: hasFlowPath ( source . asPathNode1 ( ) , sink . asPathNode1 ( ) ) and
7074 overflowSink ( exp , sink .getNode ( ) .asExpr ( ) ) and
7175 effect = "overflow"
7276 or
73- any ( MinValueFlowConfig c ) . hasFlowPath ( source , sink ) and
77+ MinValueFlow :: hasFlowPath ( source . asPathNode2 ( ) , sink . asPathNode2 ( ) ) and
7478 underflowSink ( exp , sink .getNode ( ) .asExpr ( ) ) and
7579 effect = "underflow"
7680 ) and
7781 srctyp = source .getNode ( ) .asExpr ( ) .getType ( )
7882}
7983
8084from
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 ,
8286 string effect , Type srctyp
8387where
8488 query ( source , sink , exp , effect , srctyp ) and
0 commit comments