Skip to content

Commit 1c7d764

Browse files
committed
C#: Make most module imports private.
1 parent ad27a5a commit 1c7d764

File tree

6 files changed

+82
-42
lines changed

6 files changed

+82
-42
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
* and sink models of the Standard or a 3rd party library.
44
*/
55

6-
private import CaptureModelsSpecific
76
private import ModelGeneratorUtils
7+
private import CaptureModelsSpecific
88

99
/**
1010
* Gets the summary model of `api`, if it follows the `fluent` programming pattern (returns `this`).
1111
*/
1212
string captureQualifierFlow(TargetApi api) {
13-
exists(ReturnNodeExt ret |
13+
exists(DataFlowImplCommon::ReturnNodeExt ret |
1414
api = returnNodeEnclosingCallable(ret) and
1515
isOwnInstanceAccessNode(ret)
1616
) and
@@ -47,7 +47,7 @@ private class ThroughFlowConfig extends TaintTracking::Configuration {
4747
}
4848

4949
override predicate isSink(DataFlow::Node sink, DataFlow::FlowState state) {
50-
sink instanceof ReturnNodeExt and
50+
sink instanceof DataFlowImplCommon::ReturnNodeExt and
5151
not isOwnInstanceAccessNode(sink) and
5252
not exists(captureQualifierFlow(sink.asExpr().getEnclosingCallable())) and
5353
(state instanceof TaintRead or state instanceof TaintStore)
@@ -57,15 +57,15 @@ private class ThroughFlowConfig extends TaintTracking::Configuration {
5757
DataFlow::Node node1, DataFlow::FlowState state1, DataFlow::Node node2,
5858
DataFlow::FlowState state2
5959
) {
60-
exists(TypedContent tc |
61-
store(node1, tc, node2, _) and
60+
exists(DataFlowImplCommon::TypedContent tc |
61+
DataFlowImplCommon::store(node1, tc, node2, _) and
6262
isRelevantContent(tc.getContent()) and
6363
(state1 instanceof TaintRead or state1 instanceof TaintStore) and
6464
state2 instanceof TaintStore
6565
)
6666
or
6767
exists(DataFlow::Content c |
68-
readStep(node1, c, node2) and
68+
DataFlowPrivate::readStep(node1, c, node2) and
6969
isRelevantContent(c) and
7070
state1 instanceof TaintRead and
7171
state2 instanceof TaintRead
@@ -86,8 +86,8 @@ private class ThroughFlowConfig extends TaintTracking::Configuration {
8686
*/
8787
string captureThroughFlow(TargetApi api) {
8888
exists(
89-
ThroughFlowConfig config, DataFlow::ParameterNode p, ReturnNodeExt returnNodeExt, string input,
90-
string output
89+
ThroughFlowConfig config, DataFlow::ParameterNode p,
90+
DataFlowImplCommon::ReturnNodeExt returnNodeExt, string input, string output
9191
|
9292
config.hasFlow(p, returnNodeExt) and
9393
returnNodeExt.getEnclosingCallable() = api and
@@ -108,11 +108,11 @@ string captureThroughFlow(TargetApi api) {
108108
private class FromSourceConfiguration extends TaintTracking::Configuration {
109109
FromSourceConfiguration() { this = "FromSourceConfiguration" }
110110

111-
override predicate isSource(DataFlow::Node source) { sourceNode(source, _) }
111+
override predicate isSource(DataFlow::Node source) { ExternalFlow::sourceNode(source, _) }
112112

113113
override predicate isSink(DataFlow::Node sink) {
114114
exists(TargetApi c |
115-
sink instanceof ReturnNodeExt and
115+
sink instanceof DataFlowImplCommon::ReturnNodeExt and
116116
sink.getEnclosingCallable() = c
117117
)
118118
}
@@ -132,7 +132,7 @@ private class FromSourceConfiguration extends TaintTracking::Configuration {
132132
string captureSource(TargetApi api) {
133133
exists(DataFlow::Node source, DataFlow::Node sink, FromSourceConfiguration config, string kind |
134134
config.hasFlow(source, sink) and
135-
sourceNode(source, kind) and
135+
ExternalFlow::sourceNode(source, kind) and
136136
api = sink.getEnclosingCallable() and
137137
result = asSourceModel(api, returnNodeAsOutput(sink), kind)
138138
)
@@ -148,7 +148,7 @@ string captureSource(TargetApi api) {
148148
private class PropagateToSinkConfiguration extends PropagateToSinkConfigurationSpecific {
149149
PropagateToSinkConfiguration() { this = "parameters or fields flowing into sinks" }
150150

151-
override predicate isSink(DataFlow::Node sink) { sinkNode(sink, _) }
151+
override predicate isSink(DataFlow::Node sink) { ExternalFlow::sinkNode(sink, _) }
152152

153153
override DataFlow::FlowFeature getAFeature() {
154154
result instanceof DataFlow::FeatureHasSourceCallContext
@@ -161,7 +161,7 @@ private class PropagateToSinkConfiguration extends PropagateToSinkConfigurationS
161161
string captureSink(TargetApi api) {
162162
exists(DataFlow::Node src, DataFlow::Node sink, PropagateToSinkConfiguration config, string kind |
163163
config.hasFlow(src, sink) and
164-
sinkNode(sink, kind) and
164+
ExternalFlow::sinkNode(sink, kind) and
165165
api = src.getEnclosingCallable() and
166166
not kind = "logging" and
167167
result = asSinkModel(api, asInputArgument(src), kind)

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
*/
44

55
import csharp
6-
import semmle.code.csharp.dataflow.ExternalFlow
7-
import semmle.code.csharp.dataflow.TaintTracking
8-
import semmle.code.csharp.dataflow.internal.DataFlowImplCommon
9-
import semmle.code.csharp.dataflow.internal.DataFlowPrivate
10-
import ModelGeneratorUtils
6+
private import semmle.code.csharp.dataflow.ExternalFlow as Ef
7+
private import semmle.code.csharp.dataflow.TaintTracking
8+
private import semmle.code.csharp.dataflow.internal.DataFlowImplCommon as Dfic
9+
private import semmle.code.csharp.dataflow.internal.DataFlowPrivate
10+
private import ModelGeneratorUtils
1111

1212
/**
1313
* Gets the enclosing callable of `ret`.
1414
*/
15-
Callable returnNodeEnclosingCallable(ReturnNodeExt ret) { result = getNodeEnclosingCallable(ret) }
15+
Callable returnNodeEnclosingCallable(Dfic::ReturnNodeExt ret) {
16+
result = Dfic::getNodeEnclosingCallable(ret)
17+
}
1618

1719
/**
1820
* Holds if `node` is an own instance access.
@@ -49,3 +51,17 @@ string asInputArgument(DataFlow::Node source) {
4951
source.asExpr() instanceof FieldAccess and
5052
result = qualifierString()
5153
}
54+
55+
module DataFlowImplCommon {
56+
predicate store = Dfic::store/4;
57+
58+
class ReturnNodeExt = Dfic::ReturnNodeExt;
59+
60+
class TypedContent = Dfic::TypedContent;
61+
}
62+
63+
module ExternalFlow {
64+
predicate sourceNode = Ef::sourceNode/2;
65+
66+
predicate sinkNode = Ef::sinkNode/2;
67+
}

csharp/ql/src/utils/model-generator/internal/ModelGeneratorUtils.qll

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ModelGeneratorUtilsSpecific
55
*/
66
predicate isRelevantTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
77
exists(DataFlow::Content f |
8-
readStep(node1, f, node2) and
8+
DataFlowPrivate::readStep(node1, f, node2) and
99
if f instanceof DataFlow::FieldContent
1010
then isRelevantType(f.(DataFlow::FieldContent).getField().getType())
1111
else
@@ -14,7 +14,9 @@ predicate isRelevantTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
1414
else any()
1515
)
1616
or
17-
exists(DataFlow::Content f | storeStep(node1, f, node2) | containerContent(f))
17+
exists(DataFlow::Content f | DataFlowPrivate::storeStep(node1, f, node2) |
18+
DataFlowPrivate::containerContent(f)
19+
)
1820
}
1921

2022
/**
@@ -24,7 +26,7 @@ predicate isRelevantTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
2426
predicate isRelevantContent(DataFlow::Content c) {
2527
isRelevantType(c.(DataFlow::FieldContent).getField().getType()) or
2628
isRelevantType(c.(DataFlow::SyntheticFieldContent).getField().getType()) or
27-
containerContent(c)
29+
DataFlowPrivate::containerContent(c)
2830
}
2931

3032
/**

csharp/ql/src/utils/model-generator/internal/ModelGeneratorUtilsSpecific.qll

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import csharp
2-
import semmle.code.csharp.dataflow.internal.DataFlowPrivate
3-
private import semmle.code.csharp.commons.Util
2+
private import semmle.code.csharp.dataflow.internal.DataFlowPrivate as Dfp
3+
private import semmle.code.csharp.commons.Util as Util
44
private import semmle.code.csharp.commons.Collections
55
private import semmle.code.csharp.dataflow.internal.DataFlowImplCommon
66
private import semmle.code.csharp.dataflow.internal.DataFlowDispatch
77

88
/**
99
* Holds if it is relevant to generate models for `api`.
1010
*/
11-
predicate isRelevantForModels(Callable api) { not api instanceof MainMethod }
11+
predicate isRelevantForModels(Callable api) { not api instanceof Util::MainMethod }
1212

1313
/**
1414
* A class of callables that are relevant generating summary, source and sinks models for.
@@ -24,7 +24,7 @@ class TargetApi extends DataFlowCallable {
2424
}
2525
}
2626

27-
predicate asPartialModel = Csv::asPartialModel/1;
27+
predicate asPartialModel = Dfp::Csv::asPartialModel/1;
2828

2929
/**
3030
* Holds for type `t` for fields that are relevant as an intermediate
@@ -44,7 +44,7 @@ private string parameterAccess(Parameter p) {
4444
string parameterNodeAsInput(DataFlow::ParameterNode p) {
4545
result = parameterAccess(p.asParameter())
4646
or
47-
result = "Argument[Qualifier]" and p instanceof InstanceParameterNode
47+
result = "Argument[Qualifier]" and p instanceof Dfp::InstanceParameterNode
4848
}
4949

5050
pragma[nomagic]
@@ -66,3 +66,11 @@ string returnNodeAsOutput(ReturnNodeExt node) {
6666
result = "Argument[Qualifier]"
6767
)
6868
}
69+
70+
module DataFlowPrivate {
71+
predicate containerContent = Dfp::containerContent/1;
72+
73+
predicate readStep = Dfp::readStep/3;
74+
75+
predicate storeStep = Dfp::storeStep/3;
76+
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ private import ModelGeneratorUtils
1010
* Gets the summary model of `api`, if it follows the `fluent` programming pattern (returns `this`).
1111
*/
1212
string captureQualifierFlow(TargetApi api) {
13-
exists(ReturnNodeExt ret |
13+
exists(DataFlowImplCommon::ReturnNodeExt ret |
1414
api = returnNodeEnclosingCallable(ret) and
1515
isOwnInstanceAccessNode(ret)
1616
) and
@@ -47,7 +47,7 @@ private class ThroughFlowConfig extends TaintTracking::Configuration {
4747
}
4848

4949
override predicate isSink(DataFlow::Node sink, DataFlow::FlowState state) {
50-
sink instanceof ReturnNodeExt and
50+
sink instanceof DataFlowImplCommon::ReturnNodeExt and
5151
not isOwnInstanceAccessNode(sink) and
5252
not exists(captureQualifierFlow(sink.asExpr().getEnclosingCallable())) and
5353
(state instanceof TaintRead or state instanceof TaintStore)
@@ -57,8 +57,8 @@ private class ThroughFlowConfig extends TaintTracking::Configuration {
5757
DataFlow::Node node1, DataFlow::FlowState state1, DataFlow::Node node2,
5858
DataFlow::FlowState state2
5959
) {
60-
exists(TypedContent tc |
61-
store(node1, tc, node2, _) and
60+
exists(DataFlowImplCommon::TypedContent tc |
61+
DataFlowImplCommon::store(node1, tc, node2, _) and
6262
isRelevantContent(tc.getContent()) and
6363
(state1 instanceof TaintRead or state1 instanceof TaintStore) and
6464
state2 instanceof TaintStore
@@ -86,8 +86,8 @@ private class ThroughFlowConfig extends TaintTracking::Configuration {
8686
*/
8787
string captureThroughFlow(TargetApi api) {
8888
exists(
89-
ThroughFlowConfig config, DataFlow::ParameterNode p, ReturnNodeExt returnNodeExt, string input,
90-
string output
89+
ThroughFlowConfig config, DataFlow::ParameterNode p,
90+
DataFlowImplCommon::ReturnNodeExt returnNodeExt, string input, string output
9191
|
9292
config.hasFlow(p, returnNodeExt) and
9393
returnNodeExt.getEnclosingCallable() = api and
@@ -108,11 +108,11 @@ string captureThroughFlow(TargetApi api) {
108108
private class FromSourceConfiguration extends TaintTracking::Configuration {
109109
FromSourceConfiguration() { this = "FromSourceConfiguration" }
110110

111-
override predicate isSource(DataFlow::Node source) { sourceNode(source, _) }
111+
override predicate isSource(DataFlow::Node source) { ExternalFlow::sourceNode(source, _) }
112112

113113
override predicate isSink(DataFlow::Node sink) {
114114
exists(TargetApi c |
115-
sink instanceof ReturnNodeExt and
115+
sink instanceof DataFlowImplCommon::ReturnNodeExt and
116116
sink.getEnclosingCallable() = c
117117
)
118118
}
@@ -132,7 +132,7 @@ private class FromSourceConfiguration extends TaintTracking::Configuration {
132132
string captureSource(TargetApi api) {
133133
exists(DataFlow::Node source, DataFlow::Node sink, FromSourceConfiguration config, string kind |
134134
config.hasFlow(source, sink) and
135-
sourceNode(source, kind) and
135+
ExternalFlow::sourceNode(source, kind) and
136136
api = sink.getEnclosingCallable() and
137137
result = asSourceModel(api, returnNodeAsOutput(sink), kind)
138138
)
@@ -148,7 +148,7 @@ string captureSource(TargetApi api) {
148148
private class PropagateToSinkConfiguration extends PropagateToSinkConfigurationSpecific {
149149
PropagateToSinkConfiguration() { this = "parameters or fields flowing into sinks" }
150150

151-
override predicate isSink(DataFlow::Node sink) { sinkNode(sink, _) }
151+
override predicate isSink(DataFlow::Node sink) { ExternalFlow::sinkNode(sink, _) }
152152

153153
override DataFlow::FlowFeature getAFeature() {
154154
result instanceof DataFlow::FeatureHasSourceCallContext
@@ -161,7 +161,7 @@ private class PropagateToSinkConfiguration extends PropagateToSinkConfigurationS
161161
string captureSink(TargetApi api) {
162162
exists(DataFlow::Node src, DataFlow::Node sink, PropagateToSinkConfiguration config, string kind |
163163
config.hasFlow(src, sink) and
164-
sinkNode(sink, kind) and
164+
ExternalFlow::sinkNode(sink, kind) and
165165
api = src.getEnclosingCallable() and
166166
not kind = "logging" and
167167
result = asSinkModel(api, asInputArgument(src), kind)

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
*/
44

55
import java
6-
import semmle.code.java.dataflow.ExternalFlow
6+
private import semmle.code.java.dataflow.ExternalFlow as Ef
77
import semmle.code.java.dataflow.TaintTracking
8-
import semmle.code.java.dataflow.internal.DataFlowImplCommon
8+
private import semmle.code.java.dataflow.internal.DataFlowImplCommon as Dfic
99
import semmle.code.java.dataflow.internal.DataFlowNodes
1010
import semmle.code.java.dataflow.internal.DataFlowPrivate
1111
import semmle.code.java.dataflow.InstanceAccess
@@ -14,8 +14,8 @@ import ModelGeneratorUtils
1414
/**
1515
* Gets the enclosing callable of `ret`.
1616
*/
17-
Callable returnNodeEnclosingCallable(ReturnNodeExt ret) {
18-
result = getNodeEnclosingCallable(ret).asCallable()
17+
Callable returnNodeEnclosingCallable(Dfic::ReturnNodeExt ret) {
18+
result = Dfic::getNodeEnclosingCallable(ret).asCallable()
1919
}
2020

2121
/**
@@ -60,3 +60,17 @@ string asInputArgument(DataFlow::Node source) {
6060
source.asExpr() instanceof FieldAccess and
6161
result = qualifierString()
6262
}
63+
64+
module DataFlowImplCommon {
65+
predicate store = Dfic::store/4;
66+
67+
class ReturnNodeExt = Dfic::ReturnNodeExt;
68+
69+
class TypedContent = Dfic::TypedContent;
70+
}
71+
72+
module ExternalFlow {
73+
predicate sourceNode = Ef::sourceNode/2;
74+
75+
predicate sinkNode = Ef::sinkNode/2;
76+
}

0 commit comments

Comments
 (0)