Skip to content

Commit fd311d5

Browse files
committed
Java: Add some summary debugging queries.
1 parent ae013ba commit fd311d5

File tree

4 files changed

+70
-7
lines changed

4 files changed

+70
-7
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @name Capture Summary Models Partial Path
3+
* @description Capture Summary Models Partial Path
4+
* @kind path-problem
5+
* @precision low
6+
* @id java/utils/modelgenerator/summary-models-partial-path
7+
* @severity info
8+
* @tags modelgenerator
9+
*/
10+
11+
import java
12+
import semmle.code.java.dataflow.DataFlow
13+
import utils.modelgenerator.internal.CaptureModels
14+
import PartialFlow::PartialPathGraph
15+
16+
int explorationLimit() { result = 3 }
17+
18+
module PartialFlow = PropagateFlow::FlowExplorationFwd<explorationLimit/0>;
19+
20+
from
21+
PartialFlow::PartialPathNode source, PartialFlow::PartialPathNode sink,
22+
DataFlowSummaryTargetApi api, DataFlow::ParameterNode p
23+
where
24+
PartialFlow::partialFlow(source, sink, _) and
25+
p = source.getNode() and
26+
p.asParameter() = api.getParameter(0)
27+
select sink.getNode(), source, sink, "There is flow from a $@ to $@.", source.getNode(),
28+
"parameter", sink.getNode(), "intermediate value"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @name Capture Summary Models Path
3+
* @description Capture Summary Models Path
4+
* @kind path-problem
5+
* @precision low
6+
* @id java/utils/modelgenerator/summary-models-path
7+
* @severity warning
8+
* @tags modelgenerator
9+
*/
10+
11+
import java
12+
import semmle.code.java.dataflow.DataFlow
13+
import utils.modelgenerator.internal.CaptureModels
14+
import PropagateFlow::PathGraph
15+
16+
from
17+
PropagateFlow::PathNode source, PropagateFlow::PathNode sink, DataFlowSummaryTargetApi api,
18+
DataFlow::Node p, DataFlow::Node returnNodeExt
19+
where
20+
PropagateFlow::flowPath(source, sink) and
21+
p = source.getNode() and
22+
returnNodeExt = sink.getNode() and
23+
exists(captureThroughFlow0(api, p, returnNodeExt))
24+
select sink.getNode(), source, sink, "There is flow from $@ to the $@.", source.getNode(),
25+
"parameter", sink.getNode(), "return value"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The queries in this directory are purely used for model generator debugging purposes in VS Code.

java/ql/src/utils/modelgenerator/internal/CaptureModels.qll

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,13 @@ module PropagateFlowConfig implements DataFlow::StateConfigSig {
196196
}
197197
}
198198

199-
private module PropagateFlow = TaintTracking::GlobalWithState<PropagateFlowConfig>;
199+
module PropagateFlow = TaintTracking::GlobalWithState<PropagateFlowConfig>;
200200

201-
/**
202-
* Gets the summary model(s) of `api`, if there is flow from parameters to return value or parameter.
203-
*/
204-
string captureThroughFlow(DataFlowSummaryTargetApi api) {
205-
exists(DataFlow::ParameterNode p, ReturnNodeExt returnNodeExt, string input, string output |
206-
PropagateFlow::flow(p, returnNodeExt) and
201+
string captureThroughFlow0(
202+
DataFlowSummaryTargetApi api, DataFlow::ParameterNode p, ReturnNodeExt returnNodeExt
203+
) {
204+
exists(string input, string output |
205+
p.getEnclosingCallable() = api and
207206
returnNodeExt.(DataFlow::Node).getEnclosingCallable() = api and
208207
input = parameterNodeAsInput(p) and
209208
output = returnNodeExt.getOutput() and
@@ -212,6 +211,16 @@ string captureThroughFlow(DataFlowSummaryTargetApi api) {
212211
)
213212
}
214213

214+
/**
215+
* Gets the summary model(s) of `api`, if there is flow from parameters to return value or parameter.
216+
*/
217+
string captureThroughFlow(DataFlowSummaryTargetApi api) {
218+
exists(DataFlow::ParameterNode p, ReturnNodeExt returnNodeExt |
219+
PropagateFlow::flow(p, returnNodeExt) and
220+
result = captureThroughFlow0(api, p, returnNodeExt)
221+
)
222+
}
223+
215224
/**
216225
* A dataflow configuration used for finding new sources.
217226
* The sources are the already known existing sources and the sinks are the API return nodes.

0 commit comments

Comments
 (0)