Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 852d8a2

Browse files
committed
Java: Collapse all the shared code for summary, source and sink models into a single file.
1 parent 4f2227f commit 852d8a2

6 files changed

Lines changed: 66 additions & 65 deletions

File tree

java/ql/src/utils/model-generator/CaptureSummaryModels.qll renamed to java/ql/src/utils/model-generator/CaptureModels.qll

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
/**
2-
* Provides classes and predicates related to capturing summary models
3-
* of the Standard or a 3rd party library.
2+
* Provides classes and predicates related to capturing summary, source,
3+
* and sink models of the Standard or a 3rd party library.
44
*/
55

6-
import CaptureSummaryModelsSpecific
6+
private import CaptureSummaryModelsSpecific
7+
private import CaptureSinkModelsSpecific
8+
private import CaptureSourceModelsSpecific
9+
private import ModelGeneratorUtils
710

811
/**
912
* Gets the summary model of `api`, if it follows the `fluent` programming pattern (returns `this`).
@@ -96,3 +99,59 @@ string captureThroughFlow(TargetApi api) {
9699
result = asTaintModel(api, input, output)
97100
)
98101
}
102+
103+
private class FromSourceConfiguration extends TaintTracking::Configuration {
104+
FromSourceConfiguration() { this = "FromSourceConfiguration" }
105+
106+
override predicate isSource(DataFlow::Node source) { sourceNode(source, _) }
107+
108+
override predicate isSink(DataFlow::Node sink) {
109+
exists(TargetApi c |
110+
sink instanceof ReturnNodeExt and
111+
sink.getEnclosingCallable() = c
112+
)
113+
}
114+
115+
override DataFlow::FlowFeature getAFeature() {
116+
result instanceof DataFlow::FeatureHasSinkCallContext
117+
}
118+
119+
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
120+
isRelevantTaintStep(node1, node2)
121+
}
122+
}
123+
124+
/**
125+
* Gets the source model(s) of `api`, if there is flow from an existing known source to the return of `api`.
126+
*/
127+
string captureSource(TargetApi api) {
128+
exists(DataFlow::Node source, DataFlow::Node sink, FromSourceConfiguration config, string kind |
129+
config.hasFlow(source, sink) and
130+
sourceNode(source, kind) and
131+
api = sink.getEnclosingCallable() and
132+
result = asSourceModel(api, returnNodeAsOutput(sink), kind)
133+
)
134+
}
135+
136+
private class PropagateToSinkConfiguration extends PropagateToSinkConfigurationSpecific {
137+
PropagateToSinkConfiguration() { this = "parameters or fields flowing into sinks" }
138+
139+
override predicate isSink(DataFlow::Node sink) { sinkNode(sink, _) }
140+
141+
override DataFlow::FlowFeature getAFeature() {
142+
result instanceof DataFlow::FeatureHasSourceCallContext
143+
}
144+
}
145+
146+
/**
147+
* Gets the sink model(s) of `api`, if there is flow from a parameter to an existing known sink.
148+
*/
149+
string captureSink(TargetApi api) {
150+
exists(DataFlow::Node src, DataFlow::Node sink, PropagateToSinkConfiguration config, string kind |
151+
config.hasFlow(src, sink) and
152+
sinkNode(sink, kind) and
153+
api = src.getEnclosingCallable() and
154+
not kind = "logging" and
155+
result = asSinkModel(api, asInputArgument(src), kind)
156+
)
157+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
private import ModelGeneratorUtils
8-
private import CaptureSinkModels
8+
private import CaptureModels
99

1010
from TargetApi api, string sink
1111
where sink = captureSink(api)

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

Lines changed: 0 additions & 24 deletions
This file was deleted.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
private import ModelGeneratorUtils
8-
private import CaptureSourceModels
8+
private import CaptureModels
99

1010
from TargetApi api, string sink
1111
where sink = captureSource(api)

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

Lines changed: 0 additions & 35 deletions
This file was deleted.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
* @id java/utils/model-generator/summary-models
55
*/
66

7-
private import CaptureSummaryModels
7+
private import ModelGeneratorUtils
8+
private import CaptureModels
89

910
/**
1011
* Capture fluent APIs that return `this`.

0 commit comments

Comments
 (0)