Skip to content

Commit ad90c55

Browse files
committed
C#: Improve encapsulation in CaptureModelsSpecific.
1 parent 26d5eb6 commit ad90c55

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,25 @@
22
* Provides predicates related to capturing summary models of the Standard or a 3rd party library.
33
*/
44

5-
import csharp
6-
private import semmle.code.csharp.dataflow.TaintTracking
5+
private import csharp as CS
76
private import semmle.code.csharp.commons.Util as Util
8-
private import semmle.code.csharp.commons.Collections
7+
private import semmle.code.csharp.commons.Collections as Collections
98
private import semmle.code.csharp.dataflow.internal.DataFlowDispatch
109
import semmle.code.csharp.dataflow.ExternalFlow as ExternalFlow
1110
import semmle.code.csharp.dataflow.internal.DataFlowImplCommon as DataFlowImplCommon
1211
import semmle.code.csharp.dataflow.internal.DataFlowPrivate as DataFlowPrivate
1312

13+
module DataFlow = CS::DataFlow;
14+
15+
module TaintTracking = CS::TaintTracking;
16+
17+
class Type = CS::Type;
18+
1419
/**
1520
* Holds if it is relevant to generate models for `api`.
1621
*/
17-
private predicate isRelevantForModels(Callable api) {
18-
[api.(Modifiable), api.(Accessor).getDeclaration()].isEffectivelyPublic() and
22+
private predicate isRelevantForModels(CS::Callable api) {
23+
[api.(CS::Modifiable), api.(CS::Accessor).getDeclaration()].isEffectivelyPublic() and
1924
not api instanceof Util::MainMethod
2025
}
2126

@@ -38,10 +43,10 @@ predicate asPartialModel = DataFlowPrivate::Csv::asPartialModel/1;
3843
* Holds for type `t` for fields that are relevant as an intermediate
3944
* read or write step in the data flow analysis.
4045
*/
41-
predicate isRelevantType(Type t) { not t instanceof Enum }
46+
predicate isRelevantType(CS::Type t) { not t instanceof CS::Enum }
4247

43-
private string parameterAccess(Parameter p) {
44-
if isCollectionType(p.getType())
48+
private string parameterAccess(CS::Parameter p) {
49+
if Collections::isCollectionType(p.getType())
4550
then result = "Argument[" + p.getPosition() + "].Element"
4651
else result = "Argument[" + p.getPosition() + "]"
4752
}
@@ -56,7 +61,7 @@ string parameterNodeAsInput(DataFlow::ParameterNode p) {
5661
}
5762

5863
pragma[nomagic]
59-
private Parameter getParameter(DataFlowImplCommon::ReturnNodeExt node, ParameterPosition pos) {
64+
private CS::Parameter getParameter(DataFlowImplCommon::ReturnNodeExt node, ParameterPosition pos) {
6065
result = node.getEnclosingCallable().getParameter(pos.getPosition())
6166
}
6267

@@ -80,15 +85,15 @@ string returnNodeAsOutput(DataFlowImplCommon::ReturnNodeExt node) {
8085
/**
8186
* Gets the enclosing callable of `ret`.
8287
*/
83-
Callable returnNodeEnclosingCallable(DataFlowImplCommon::ReturnNodeExt ret) {
88+
CS::Callable returnNodeEnclosingCallable(DataFlowImplCommon::ReturnNodeExt ret) {
8489
result = DataFlowImplCommon::getNodeEnclosingCallable(ret)
8590
}
8691

8792
/**
8893
* Holds if `node` is an own instance access.
8994
*/
9095
predicate isOwnInstanceAccessNode(DataFlowPrivate::ReturnNode node) {
91-
node.asExpr() instanceof ThisAccess
96+
node.asExpr() instanceof CS::ThisAccess
9297
}
9398

9499
/**
@@ -105,17 +110,17 @@ predicate isRelevantSinkKind(string kind) { any() }
105110
/**
106111
* Language specific parts of the `PropagateToSinkConfiguration`.
107112
*/
108-
class PropagateToSinkConfigurationSpecific extends TaintTracking::Configuration {
113+
class PropagateToSinkConfigurationSpecific extends CS::TaintTracking::Configuration {
109114
PropagateToSinkConfigurationSpecific() { this = "parameters or fields flowing into sinks" }
110115

111116
private predicate isRelevantMemberAccess(DataFlow::Node node) {
112-
exists(MemberAccess access | access = node.asExpr() |
117+
exists(CS::MemberAccess access | access = node.asExpr() |
113118
access.hasThisQualifier() and
114119
access.getTarget().isEffectivelyPublic() and
115120
(
116-
access instanceof FieldAccess
121+
access instanceof CS::FieldAccess
117122
or
118-
access.getTarget().(Property).getSetter().isPublic()
123+
access.getTarget().(CS::Property).getSetter().isPublic()
119124
)
120125
)
121126
}

0 commit comments

Comments
 (0)