15
15
import java
16
16
import semmle.code.java.dataflow.FlowSources
17
17
import NumericCastCommon
18
- import DataFlow:: PathGraph
19
18
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 }
26
21
27
- override predicate isSink ( DataFlow:: Node sink ) {
22
+ predicate isSink ( DataFlow:: Node sink ) {
28
23
sink .asExpr ( ) = any ( NumericNarrowingCastExpr cast ) .getExpr ( )
29
24
}
30
25
31
- override predicate isSanitizer ( DataFlow:: Node node ) {
26
+ predicate isBarrier ( DataFlow:: Node node ) {
32
27
boundedRead ( node .asExpr ( ) ) or
33
28
castCheck ( node .asExpr ( ) ) or
34
29
node .getType ( ) instanceof SmallType or
@@ -37,13 +32,17 @@ private class NumericCastFlowConfig extends TaintTracking::Configuration {
37
32
}
38
33
}
39
34
35
+ module NumericCastFlow = TaintTracking:: Make< NumericCastFlowConfig > ;
36
+
37
+ import NumericCastFlow:: PathGraph
38
+
40
39
from
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
43
42
where
44
43
exp .getExpr ( ) = tainted and
45
44
sink .getNode ( ) .asExpr ( ) = tainted and
46
- conf . hasFlowPath ( source , sink ) and
45
+ NumericCastFlow :: hasFlowPath ( source , sink ) and
47
46
not exists ( RightShiftOp e | e .getShiftedVariable ( ) = tainted .getVariable ( ) )
48
47
select exp , source , sink ,
49
48
"This cast to a narrower type depends on a $@, potentially causing truncation." , source .getNode ( ) ,
0 commit comments