|
13 | 13 |
|
14 | 14 | import java |
15 | 15 | import ArraySizing |
16 | | -import DataFlow::PathGraph |
| 16 | +import semmle.code.java.dataflow.TaintTracking |
17 | 17 |
|
18 | | -class BoundedFlowSourceConf extends DataFlow::Configuration { |
19 | | - BoundedFlowSourceConf() { this = "BoundedFlowSource" } |
20 | | - |
21 | | - override predicate isSource(DataFlow::Node source) { |
| 18 | +module BoundedFlowSourceConfig implements DataFlow::ConfigSig { |
| 19 | + predicate isSource(DataFlow::Node source) { |
22 | 20 | source instanceof BoundedFlowSource and |
23 | 21 | // There is not a fixed lower bound which is greater than zero. |
24 | 22 | not source.(BoundedFlowSource).lowerBound() > 0 |
25 | 23 | } |
26 | 24 |
|
27 | | - override predicate isSink(DataFlow::Node sink) { |
| 25 | + predicate isSink(DataFlow::Node sink) { |
28 | 26 | any(CheckableArrayAccess caa).canThrowOutOfBoundsDueToEmptyArray(sink.asExpr(), _) |
29 | 27 | } |
30 | 28 | } |
31 | 29 |
|
| 30 | +module BoundedFlowSourceFlow = DataFlow::Make<BoundedFlowSourceConfig>; |
| 31 | + |
| 32 | +import BoundedFlowSourceFlow::PathGraph |
| 33 | + |
32 | 34 | from |
33 | | - DataFlow::PathNode source, DataFlow::PathNode sink, BoundedFlowSource boundedsource, |
34 | | - Expr sizeExpr, ArrayCreationExpr arrayCreation, CheckableArrayAccess arrayAccess |
| 35 | + BoundedFlowSourceFlow::PathNode source, BoundedFlowSourceFlow::PathNode sink, |
| 36 | + BoundedFlowSource boundedsource, Expr sizeExpr, ArrayCreationExpr arrayCreation, |
| 37 | + CheckableArrayAccess arrayAccess |
35 | 38 | where |
36 | 39 | arrayAccess.canThrowOutOfBoundsDueToEmptyArray(sizeExpr, arrayCreation) and |
37 | 40 | sizeExpr = sink.getNode().asExpr() and |
38 | 41 | boundedsource = source.getNode() and |
39 | | - any(BoundedFlowSourceConf conf).hasFlowPath(source, sink) |
| 42 | + BoundedFlowSourceFlow::hasFlowPath(source, sink) |
40 | 43 | select arrayAccess.getIndexExpr(), source, sink, |
41 | 44 | "This accesses the $@, but the array is initialized using $@ which may be zero.", arrayCreation, |
42 | 45 | "array", boundedsource, boundedsource.getDescription().toLowerCase() |
0 commit comments