Skip to content

Commit 13a802e

Browse files
committed
Java: Sync files and make adjusting changes.
1 parent dd44d71 commit 13a802e

File tree

7 files changed

+34
-25
lines changed

7 files changed

+34
-25
lines changed

java/ql/src/utils/model-generator/CaptureNegativeSummaryModels.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* @tags model-generator
77
*/
88

9-
private import internal.CaptureModels
10-
private import internal.CaptureSummaryFlow
9+
import internal.CaptureModels
10+
import internal.CaptureSummaryFlow
1111

12-
from TargetApi api, string noflow
12+
from DataFlowTargetApi api, string noflow
1313
where noflow = captureNoFlow(api)
1414
select noflow order by noflow

java/ql/src/utils/model-generator/CaptureSinkModels.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* @tags model-generator
77
*/
88

9-
private import internal.CaptureModels
9+
import internal.CaptureModels
1010

11-
from TargetApi api, string sink
11+
from DataFlowTargetApi api, string sink
1212
where sink = captureSink(api)
1313
select sink order by sink

java/ql/src/utils/model-generator/CaptureSourceModels.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* @tags model-generator
77
*/
88

9-
private import internal.CaptureModels
9+
import internal.CaptureModels
1010

11-
from TargetApi api, string source
11+
from DataFlowTargetApi api, string source
1212
where source = captureSource(api)
1313
select source order by source

java/ql/src/utils/model-generator/CaptureSummaryModels.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* @tags model-generator
77
*/
88

9-
private import internal.CaptureModels
10-
private import internal.CaptureSummaryFlow
9+
import internal.CaptureModels
10+
import internal.CaptureSummaryFlow
1111

12-
from TargetApi api, string flow
12+
from DataFlowTargetApi api, string flow
1313
where flow = captureFlow(api)
1414
select flow order by flow

java/ql/src/utils/model-generator/internal/CaptureModels.qll

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
private import CaptureModelsSpecific
77

8-
class TargetApi = TargetApiSpecific;
8+
class DataFlowTargetApi extends TargetApiSpecific {
9+
DataFlowTargetApi() { isRelevantForFlowModels(this) }
10+
}
911

1012
/**
1113
* Holds if data can flow from `node1` to `node2` either via a read or a write of an intermediate field `f`.
@@ -40,37 +42,39 @@ private predicate isRelevantContent(DataFlow::Content c) {
4042
* Gets the summary model for `api` with `input`, `output` and `kind`.
4143
*/
4244
bindingset[input, output, kind]
43-
private string asSummaryModel(TargetApi api, string input, string output, string kind) {
45+
private string asSummaryModel(TargetApiSpecific api, string input, string output, string kind) {
4446
result =
4547
asPartialModel(api) + input + ";" //
4648
+ output + ";" //
4749
+ kind + ";" //
4850
+ "generated"
4951
}
5052

51-
string asNegativeSummaryModel(TargetApi api) { result = asPartialNegativeModel(api) + "generated" }
53+
string asNegativeSummaryModel(TargetApiSpecific api) {
54+
result = asPartialNegativeModel(api) + "generated"
55+
}
5256

5357
/**
5458
* Gets the value summary model for `api` with `input` and `output`.
5559
*/
5660
bindingset[input, output]
57-
private string asValueModel(TargetApi api, string input, string output) {
61+
private string asValueModel(TargetApiSpecific api, string input, string output) {
5862
result = asSummaryModel(api, input, output, "value")
5963
}
6064

6165
/**
6266
* Gets the taint summary model for `api` with `input` and `output`.
6367
*/
6468
bindingset[input, output]
65-
private string asTaintModel(TargetApi api, string input, string output) {
69+
string asTaintModel(TargetApiSpecific api, string input, string output) {
6670
result = asSummaryModel(api, input, output, "taint")
6771
}
6872

6973
/**
7074
* Gets the sink model for `api` with `input` and `kind`.
7175
*/
7276
bindingset[input, kind]
73-
private string asSinkModel(TargetApi api, string input, string kind) {
77+
private string asSinkModel(TargetApiSpecific api, string input, string kind) {
7478
result =
7579
asPartialModel(api) + input + ";" //
7680
+ kind + ";" //
@@ -81,7 +85,7 @@ private string asSinkModel(TargetApi api, string input, string kind) {
8185
* Gets the source model for `api` with `output` and `kind`.
8286
*/
8387
bindingset[output, kind]
84-
private string asSourceModel(TargetApi api, string output, string kind) {
88+
private string asSourceModel(TargetApiSpecific api, string output, string kind) {
8589
result =
8690
asPartialModel(api) + output + ";" //
8791
+ kind + ";" //
@@ -91,7 +95,7 @@ private string asSourceModel(TargetApi api, string output, string kind) {
9195
/**
9296
* Gets the summary model of `api`, if it follows the `fluent` programming pattern (returns `this`).
9397
*/
94-
string captureQualifierFlow(TargetApi api) {
98+
string captureQualifierFlow(TargetApiSpecific api) {
9599
exists(DataFlowImplCommon::ReturnNodeExt ret |
96100
api = returnNodeEnclosingCallable(ret) and
97101
isOwnInstanceAccessNode(ret)
@@ -140,7 +144,7 @@ private class ThroughFlowConfig extends TaintTracking::Configuration {
140144

141145
override predicate isSource(DataFlow::Node source, DataFlow::FlowState state) {
142146
source instanceof DataFlow::ParameterNode and
143-
source.getEnclosingCallable() instanceof TargetApi and
147+
source.getEnclosingCallable() instanceof DataFlowTargetApi and
144148
state.(TaintRead).getStep() = 0
145149
}
146150

@@ -184,7 +188,7 @@ private class ThroughFlowConfig extends TaintTracking::Configuration {
184188
/**
185189
* Gets the summary model(s) of `api`, if there is flow from parameters to return value or parameter.
186190
*/
187-
string captureThroughFlow(TargetApi api) {
191+
string captureThroughFlow(DataFlowTargetApi api) {
188192
exists(
189193
ThroughFlowConfig config, DataFlow::ParameterNode p,
190194
DataFlowImplCommon::ReturnNodeExt returnNodeExt, string input, string output
@@ -211,7 +215,7 @@ private class FromSourceConfiguration extends TaintTracking::Configuration {
211215
override predicate isSource(DataFlow::Node source) { ExternalFlow::sourceNode(source, _) }
212216

213217
override predicate isSink(DataFlow::Node sink) {
214-
exists(TargetApi c |
218+
exists(DataFlowTargetApi c |
215219
sink instanceof DataFlowImplCommon::ReturnNodeExt and
216220
sink.getEnclosingCallable() = c
217221
)
@@ -229,7 +233,7 @@ private class FromSourceConfiguration extends TaintTracking::Configuration {
229233
/**
230234
* Gets the source model(s) of `api`, if there is flow from an existing known source to the return of `api`.
231235
*/
232-
string captureSource(TargetApi api) {
236+
string captureSource(DataFlowTargetApi api) {
233237
exists(DataFlow::Node source, DataFlow::Node sink, FromSourceConfiguration config, string kind |
234238
config.hasFlow(source, sink) and
235239
ExternalFlow::sourceNode(source, kind) and
@@ -259,7 +263,7 @@ private class PropagateToSinkConfiguration extends PropagateToSinkConfigurationS
259263
/**
260264
* Gets the sink model(s) of `api`, if there is flow from a parameter to an existing known sink.
261265
*/
262-
string captureSink(TargetApi api) {
266+
string captureSink(DataFlowTargetApi api) {
263267
exists(DataFlow::Node src, DataFlow::Node sink, PropagateToSinkConfiguration config, string kind |
264268
config.hasFlow(src, sink) and
265269
ExternalFlow::sinkNode(sink, kind) and

java/ql/src/utils/model-generator/internal/CaptureModelsSpecific.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ private predicate isRelevantForModels(J::Callable api) {
5959
not api instanceof J::StaticInitializer
6060
}
6161

62+
/**
63+
* Holds if it is relevant to generate models for `api` based on data flow analysis.
64+
*/
65+
predicate isRelevantForFlowModels = isRelevantForModels/1;
66+
6267
/**
6368
* A class of Callables that are relevant for generating summary, source and sinks models for.
6469
*

java/ql/src/utils/model-generator/internal/CaptureSummaryFlow.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private import CaptureModels
6767
* Captured Model:
6868
* ```p;Foo;true;addToList;;Argument[0];Argument[1];taint```
6969
*/
70-
string captureFlow(TargetApi api) {
70+
string captureFlow(DataFlowTargetApi api) {
7171
result = captureQualifierFlow(api) or
7272
result = captureThroughFlow(api)
7373
}
@@ -76,7 +76,7 @@ string captureFlow(TargetApi api) {
7676
* Gets the negative summary for `api`, if any.
7777
* A negative summary is generated, if there does not exist any positive flow.
7878
*/
79-
string captureNoFlow(TargetApi api) {
79+
string captureNoFlow(DataFlowTargetApi api) {
8080
not exists(captureFlow(api)) and
8181
result = asNegativeSummaryModel(api)
8282
}

0 commit comments

Comments
 (0)