1515import java
1616import semmle.code.java.dataflow.FlowSources
1717import NumericCastCommon
18- import DataFlow:: PathGraph
1918
20- private class NumericCastFlowConfig extends TaintTracking:: Configuration {
21- NumericCastFlowConfig ( ) {
22- this = "NumericCastTaintedLocal::LocalUserInputToNumericNarrowingCastExpr"
23- }
24-
25- override predicate isSource ( DataFlow:: Node src ) { src instanceof LocalUserInput }
19+ module NumericCastFlowConfig implements DataFlow:: ConfigSig {
20+ predicate isSource ( DataFlow:: Node src ) { src instanceof LocalUserInput }
2621
27- override predicate isSink ( DataFlow:: Node sink ) {
22+ predicate isSink ( DataFlow:: Node sink ) {
2823 sink .asExpr ( ) = any ( NumericNarrowingCastExpr cast ) .getExpr ( )
2924 }
3025
31- override predicate isSanitizer ( DataFlow:: Node node ) {
26+ predicate isBarrier ( DataFlow:: Node node ) {
3227 boundedRead ( node .asExpr ( ) ) or
3328 castCheck ( node .asExpr ( ) ) or
3429 node .getType ( ) instanceof SmallType or
@@ -37,13 +32,17 @@ private class NumericCastFlowConfig extends TaintTracking::Configuration {
3732 }
3833}
3934
35+ module NumericCastFlow = TaintTracking:: Make< NumericCastFlowConfig > ;
36+
37+ import NumericCastFlow:: PathGraph
38+
4039from
41- DataFlow :: PathNode source , DataFlow :: PathNode sink , NumericNarrowingCastExpr exp ,
42- VarAccess tainted , NumericCastFlowConfig conf
40+ NumericCastFlow :: PathNode source , NumericCastFlow :: PathNode sink , NumericNarrowingCastExpr exp ,
41+ VarAccess tainted
4342where
4443 exp .getExpr ( ) = tainted and
4544 sink .getNode ( ) .asExpr ( ) = tainted and
46- conf . hasFlowPath ( source , sink ) and
45+ NumericCastFlow :: hasFlowPath ( source , sink ) and
4746 not exists ( RightShiftOp e | e .getShiftedVariable ( ) = tainted .getVariable ( ) )
4847select exp , source , sink ,
4948 "This cast to a narrower type depends on a $@, potentially causing truncation." , source .getNode ( ) ,
0 commit comments