Skip to content

Commit 3ad9731

Browse files
committed
C#/Java: Add some more QL docs.
1 parent 2476e71 commit 3ad9731

File tree

4 files changed

+84
-8
lines changed

4 files changed

+84
-8
lines changed

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import ModelGeneratorUtilsSpecific
22

3+
/**
4+
* Holds if data can flow from `node1` to `node2` either via a read or a write of an intermediate field `f`.
5+
*/
36
predicate isRelevantTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
47
exists(DataFlow::Content f |
58
readStep(node1, f, node2) and
@@ -14,12 +17,19 @@ predicate isRelevantTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
1417
exists(DataFlow::Content f | storeStep(node1, f, node2) | DataFlow::containerContent(f))
1518
}
1619

17-
predicate isRelevantContent(DataFlow::Content f) {
18-
isRelevantType(f.(DataFlow::FieldContent).getField().getType()) or
19-
isRelevantType(f.(DataFlow::FieldContent).getField().getType()) or
20-
DataFlow::containerContent(f)
20+
/**
21+
* Holds if content `c` is either a field or synthetic field of a relevant type
22+
* or a container like content.
23+
*/
24+
predicate isRelevantContent(DataFlow::Content c) {
25+
isRelevantType(c.(DataFlow::FieldContent).getField().getType()) or
26+
isRelevantType(c.(DataFlow::FieldContent).getField().getType()) or
27+
DataFlow::containerContent(c)
2128
}
2229

30+
/**
31+
* Gets the summary model for `api` with `input`, `output` and `kind`.
32+
*/
2333
bindingset[input, output, kind]
2434
string asSummaryModel(TargetAPI api, string input, string output, string kind) {
2535
result =
@@ -28,21 +38,33 @@ string asSummaryModel(TargetAPI api, string input, string output, string kind) {
2838
+ kind
2939
}
3040

41+
/**
42+
* Gets the value summary model for `api` with `input` and `output`.
43+
*/
3144
bindingset[input, output]
3245
string asValueModel(TargetAPI api, string input, string output) {
3346
result = asSummaryModel(api, input, output, "value")
3447
}
3548

49+
/**
50+
* Gets the taint summary model for `api` with `input` and `output`.
51+
*/
3652
bindingset[input, output]
3753
string asTaintModel(TargetAPI api, string input, string output) {
3854
result = asSummaryModel(api, input, output, "taint")
3955
}
4056

57+
/**
58+
* Gets the sink model for `api` with `input` and `kind`.
59+
*/
4160
bindingset[input, kind]
4261
string asSinkModel(TargetAPI api, string input, string kind) {
4362
result = asPartialModel(api) + input + ";" + kind
4463
}
4564

65+
/**
66+
* Gets the source model for `api` with `output` and `kind`.
67+
*/
4668
bindingset[output, kind]
4769
string asSourceModel(TargetAPI api, string output, string kind) {
4870
result = asPartialModel(api) + output + ";" + kind

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ private import semmle.code.csharp.dataflow.internal.DataFlowDispatch
66

77
private predicate isRelevantForModels(Callable api) { not api instanceof MainMethod }
88

9+
/**
10+
* A class of Callables that are relevant for generating summary, source and sinks models for.
11+
*
12+
* In the Standard library and 3rd party libraries it the Callables that can be called
13+
* from outside the library itself.
14+
*/
915
class TargetAPI extends Callable {
1016
TargetAPI() {
1117
[this.(Modifiable), this.(Accessor).getDeclaration()].isEffectivelyPublic() and
@@ -53,6 +59,10 @@ string asPartialModel(TargetAPI api) {
5359
)
5460
}
5561

62+
/**
63+
* Holds for type `t` for fields that are relevant as an intermediate
64+
* read or write step in the data flow analysis.
65+
*/
5666
predicate isRelevantType(Type t) { not t instanceof Enum }
5767

5868
private predicate isPrimitiveTypeUsedForBulkData(Type t) {
@@ -67,12 +77,18 @@ private string parameterAccess(Parameter p) {
6777
else result = "Argument[" + p.getPosition() + "]"
6878
}
6979

80+
/**
81+
* Gets the model string representation of the parameter node `p`.
82+
*/
7083
string parameterNodeAsInput(DataFlow::ParameterNode p) {
7184
result = parameterAccess(p.asParameter())
7285
or
7386
result = "Argument[Qualifier]" and p instanceof InstanceParameterNode
7487
}
7588

89+
/**
90+
* Gets the model string represention of the the return node `node`.
91+
*/
7692
string returnNodeAsOutput(ReturnNodeExt node) {
7793
if node.getKind() instanceof ValueReturnKind
7894
then result = "ReturnValue"

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import ModelGeneratorUtilsSpecific
22

3+
/**
4+
* Holds if data can flow from `node1` to `node2` either via a read or a write of an intermediate field `f`.
5+
*/
36
predicate isRelevantTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
47
exists(DataFlow::Content f |
58
readStep(node1, f, node2) and
@@ -14,12 +17,19 @@ predicate isRelevantTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
1417
exists(DataFlow::Content f | storeStep(node1, f, node2) | DataFlow::containerContent(f))
1518
}
1619

17-
predicate isRelevantContent(DataFlow::Content f) {
18-
isRelevantType(f.(DataFlow::FieldContent).getField().getType()) or
19-
isRelevantType(f.(DataFlow::FieldContent).getField().getType()) or
20-
DataFlow::containerContent(f)
20+
/**
21+
* Holds if content `c` is either a field or synthetic field of a relevant type
22+
* or a container like content.
23+
*/
24+
predicate isRelevantContent(DataFlow::Content c) {
25+
isRelevantType(c.(DataFlow::FieldContent).getField().getType()) or
26+
isRelevantType(c.(DataFlow::FieldContent).getField().getType()) or
27+
DataFlow::containerContent(c)
2128
}
2229

30+
/**
31+
* Gets the summary model for `api` with `input`, `output` and `kind`.
32+
*/
2333
bindingset[input, output, kind]
2434
string asSummaryModel(TargetApi api, string input, string output, string kind) {
2535
result =
@@ -28,21 +38,33 @@ string asSummaryModel(TargetApi api, string input, string output, string kind) {
2838
+ kind
2939
}
3040

41+
/**
42+
* Gets the value summary model for `api` with `input` and `output`.
43+
*/
3144
bindingset[input, output]
3245
string asValueModel(TargetApi api, string input, string output) {
3346
result = asSummaryModel(api, input, output, "value")
3447
}
3548

49+
/**
50+
* Gets the taint summary model for `api` with `input` and `output`.
51+
*/
3652
bindingset[input, output]
3753
string asTaintModel(TargetApi api, string input, string output) {
3854
result = asSummaryModel(api, input, output, "taint")
3955
}
4056

57+
/**
58+
* Gets the sink model for `api` with `input` and `kind`.
59+
*/
4160
bindingset[input, kind]
4261
string asSinkModel(TargetApi api, string input, string kind) {
4362
result = asPartialModel(api) + input + ";" + kind
4463
}
4564

65+
/**
66+
* Gets the source model for `api` with `output` and `kind`.
67+
*/
4668
bindingset[output, kind]
4769
string asSourceModel(TargetApi api, string output, string kind) {
4870
result = asPartialModel(api) + output + ";" + kind

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ predicate isRelevantForModels(Callable api) {
4242
not api instanceof MainMethod
4343
}
4444

45+
/**
46+
* A class of Callables that are relevant for generating summary, source and sinks models for.
47+
*
48+
* In the Standard library and 3rd party libraries it the Callables that can be called
49+
* from outside the library itself.
50+
*/
4551
class TargetApi extends Callable {
4652
TargetApi() {
4753
this.isPublic() and
@@ -90,6 +96,10 @@ private predicate isPrimitiveTypeUsedForBulkData(Type t) {
9096
t.getName().regexpMatch("byte|char|Byte|Character")
9197
}
9298

99+
/**
100+
* Holds for type `t` for fields that are relevant as an intermediate
101+
* read or write step in the data flow analysis.
102+
*/
93103
predicate isRelevantType(Type t) {
94104
not t instanceof TypeClass and
95105
not t instanceof EnumType and
@@ -122,12 +132,18 @@ private string parameterAccess(Parameter p) {
122132
else result = "Argument[" + p.getPosition() + "]"
123133
}
124134

135+
/**
136+
* Gets the model string representation of the parameter node `p`.
137+
*/
125138
string parameterNodeAsInput(DataFlow::ParameterNode p) {
126139
result = parameterAccess(p.asParameter())
127140
or
128141
result = "Argument[-1]" and p instanceof DataFlow::InstanceParameterNode
129142
}
130143

144+
/**
145+
* Gets the model string represention of the the return node `node`.
146+
*/
131147
string returnNodeAsOutput(ReturnNodeExt node) {
132148
if node.getKind() instanceof ValueReturnKind
133149
then result = "ReturnValue"

0 commit comments

Comments
 (0)