Skip to content

Commit 61a2c0d

Browse files
authored
Merge pull request #10084 from aschackmull/java/numericcasttainted-barrier
Java: Move sink-constraints into the configuration in NumericCastTainted.ql.
2 parents 2afb4ab + f6eccd3 commit 61a2c0d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

java/ql/src/Security/CWE/CWE-681/NumericCastTainted.ql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,26 @@ private class NumericCastFlowConfig extends TaintTracking::Configuration {
2323
override predicate isSource(DataFlow::Node src) { src instanceof RemoteFlowSource }
2424

2525
override predicate isSink(DataFlow::Node sink) {
26-
sink.asExpr() = any(NumericNarrowingCastExpr cast).getExpr()
26+
sink.asExpr() = any(NumericNarrowingCastExpr cast).getExpr() and
27+
sink.asExpr() instanceof VarAccess
2728
}
2829

2930
override predicate isSanitizer(DataFlow::Node node) {
3031
boundedRead(node.asExpr()) or
3132
castCheck(node.asExpr()) or
3233
node.getType() instanceof SmallType or
3334
smallExpr(node.asExpr()) or
34-
node.getEnclosingCallable() instanceof HashCodeMethod
35+
node.getEnclosingCallable() instanceof HashCodeMethod or
36+
exists(RightShiftOp e | e.getShiftedVariable().getAnAccess() = node.asExpr())
3537
}
3638
}
3739

3840
from
3941
DataFlow::PathNode source, DataFlow::PathNode sink, NumericNarrowingCastExpr exp,
40-
VarAccess tainted, NumericCastFlowConfig conf
42+
NumericCastFlowConfig conf
4143
where
42-
exp.getExpr() = tainted and
43-
sink.getNode().asExpr() = tainted and
44-
conf.hasFlowPath(source, sink) and
45-
not exists(RightShiftOp e | e.getShiftedVariable() = tainted.getVariable())
44+
sink.getNode().asExpr() = exp.getExpr() and
45+
conf.hasFlowPath(source, sink)
4646
select exp, source, sink,
4747
"$@ flows to here and is cast to a narrower type, potentially causing truncation.",
4848
source.getNode(), "User-provided value"

0 commit comments

Comments
 (0)