Skip to content

Commit b7aa85b

Browse files
committed
Address some review comments
1 parent f375553 commit b7aa85b

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

ql/lib/semmle/go/dataflow/ExternalFlow.qll

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,16 @@
2323
* 7. The `input` column specifies how data enters the element selected by the
2424
* first 6 columns, and the `output` column specifies how data leaves the
2525
* element selected by the first 6 columns. An `input` can be either "",
26-
* "Argument[n]", "Argument[n1..n2]", "ReturnValue", "ReturnValue[n]",
27-
* "ReturnValue[n1..n2]":
26+
* "Argument[n]", or "Argument[n1..n2]":
2827
* - "": Selects a write to the selected element in case this is a field.
2928
* - "Argument[n]": Selects an argument in a call to the selected element.
3029
* The arguments are zero-indexed, and `-1` specifies the qualifier.
3130
* - "Argument[n1..n2]": Similar to "Argument[n]" but selects any argument
3231
* in the given range. The range is inclusive at both ends.
33-
* - "ReturnValue": Selects the first value being returned by the selected
34-
* element. This requires that the selected element is a method with a
35-
* body.
36-
* - "ReturnValue[n]": Similar to "ReturnValue" but selects the specified
37-
* return value. The return values are zero-indexed
38-
* - "ReturnValue[n1..n2]": Similar to "ReturnValue[n]" but selects any
39-
* return value in the given range. The range is inclusive at both ends.
4032
*
4133
* An `output` can be either "", "Argument[n]", "Argument[n1..n2]", "Parameter",
42-
* "Parameter[n]", "Parameter[n1..n2]", or "ReturnValue":
34+
* "Parameter[n]", "Parameter[n1..n2]", , "ReturnValue", "ReturnValue[n]", or
35+
* "ReturnValue[n1..n2]":
4336
* - "": Selects a read of a selected field, or a selected parameter.
4437
* - "Argument[n]": Selects the post-update value of an argument in a call to the
4538
* selected element. That is, the value of the argument after the call returns.
@@ -53,7 +46,13 @@
5346
* numbered parameter (zero-indexed, and `-1` specifies the value of `this`).
5447
* - "Parameter[n1..n2]": Similar to "Parameter[n]" but selects any parameter
5548
* in the given range. The range is inclusive at both ends.
56-
* - "ReturnValue": Selects the return value of a call to the selected element.
49+
* - "ReturnValue": Selects the first value being returned by the selected
50+
* element. This requires that the selected element is a method with a
51+
* body.
52+
* - "ReturnValue[n]": Similar to "ReturnValue" but selects the specified
53+
* return value. The return values are zero-indexed
54+
* - "ReturnValue[n1..n2]": Similar to "ReturnValue[n]" but selects any
55+
* return value in the given range. The range is inclusive at both ends.
5756
* 8. The `kind` column is a tag that can be referenced from QL to determine to
5857
* which classes the interpreted elements should be added. For example, for
5958
* sources "remote" indicates a default remote flow source, and for summaries
@@ -190,30 +189,45 @@ predicate summaryModel(
190189
row.splitAt(";", 8) = kind
191190
}
192191

192+
/** Holds if `package` have CSV framework coverage. */
193193
private predicate relevantPackage(string package) {
194194
sourceModel(package, _, _, _, _, _, _, _) or
195195
sinkModel(package, _, _, _, _, _, _, _) or
196196
summaryModel(package, _, _, _, _, _, _, _, _)
197197
}
198198

199+
/**
200+
* Holds if `shortpkg` and `longpkg` have CSV framework coverage and `shortpkg`
201+
* is a subpackage of `longpkg`.
202+
*/
199203
private predicate packageLink(string shortpkg, string longpkg) {
200204
relevantPackage(shortpkg) and
201205
relevantPackage(longpkg) and
202206
longpkg.prefix(longpkg.indexOf(".")) = shortpkg
203207
}
204208

209+
/**
210+
* Holds if `package` has CSV framework coverage and it is not a subpackage of
211+
* any other package with CSV framework coverage.
212+
*/
205213
private predicate canonicalPackage(string package) {
206214
relevantPackage(package) and not packageLink(_, package)
207215
}
208216

217+
/**
218+
* Holds if `package` and `subpkg` have CSV framework coverage, `subpkg` is a
219+
* subpackage of `package` (or they are the same), and `package` is not a
220+
* subpackage of any other package with CSV framework coverage.
221+
*/
209222
private predicate canonicalPkgLink(string package, string subpkg) {
210223
canonicalPackage(package) and
211224
(subpkg = package or packageLink(package, subpkg))
212225
}
213226

214227
/**
215228
* Holds if CSV framework coverage of `package` is `n` api endpoints of the
216-
* kind `(kind, part)`.
229+
* kind `(kind, part)`, and `pkgs` is the number of subpackages of `package`
230+
* which have CSV framework coverage (including `package` itself).
217231
*/
218232
predicate modelCoverage(string package, int pkgs, string kind, string part, int n) {
219233
pkgs = strictcount(string subpkg | canonicalPkgLink(package, subpkg)) and
@@ -389,7 +403,7 @@ class SyntheticField extends string {
389403
SyntheticField() { parseSynthField(_, this) }
390404

391405
/**
392-
* Gets the type of this field. The default type is `Object`, but this can be
406+
* Gets the type of this field. The default type is `interface{}`, but this can be
393407
* overridden.
394408
*/
395409
Type getType() { result instanceof EmptyInterfaceType }

ql/lib/semmle/go/dataflow/internal/ContainerFlow.qll

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ private class BuiltinModel extends SummaryModelCsv {
1717
}
1818

1919
/**
20-
* Holds if the step from `node1` to `node2` stores a value in a slice or array.
21-
* Thus, `node2` references an object with a content `c` that contains the value
22-
* of `node1`. This covers array assignments and initializers as well as
23-
* implicit array creations for varargs.
20+
* Holds if the step from `node1` to `node2` stores a value in an array, a
21+
* slice, a collection or a map. Thus, `node2` references an object with a
22+
* content `c` that contains the value of `node1`. This covers array
23+
* assignments and initializers as well as implicit array creations for
24+
* varargs.
2425
*/
2526
predicate containerStoreStep(Node node1, Node node2, Content c) {
2627
c instanceof ArrayContent and
2728
(
28-
// currently there is no database information about variadic functions
2929
(
3030
node2.getType() instanceof ArrayType or
3131
node2.getType() instanceof SliceType
@@ -46,10 +46,10 @@ predicate containerStoreStep(Node node1, Node node2, Content c) {
4646
}
4747

4848
/**
49-
* Holds if the step from `node1` to `node2` reads a value from a slice or array.
50-
* Thus, `node1` references an object with a content `c` whose value ends up in
51-
* `node2`. This covers ordinary array reads as well as array iteration through
52-
* enhanced `for` statements.
49+
* Holds if the step from `node1` to `node2` reads a value from an array, a
50+
* slice, a collection or a map. Thus, `node1` references an object with a
51+
* content `c` whose value ends up in `node2`. This covers ordinary array reads
52+
* as well as array iteration through enhanced `for` statements.
5353
*/
5454
predicate containerReadStep(Node node1, Node node2, Content c) {
5555
c instanceof ArrayContent and

0 commit comments

Comments
 (0)