Skip to content

Commit cdc1c2c

Browse files
authored
Merge pull request github#13454 from owen-mc/go/add-mad-content-for-pointer-content
Go: Add models-as-data content for pointer content
2 parents d7c97f8 + 04ff89e commit cdc1c2c

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/ExternalFlow.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
* in the given range. The range is inclusive at both ends.
6363
* - "ReturnValue": Selects the return value of a call to the selected element.
6464
*
65-
* For summaries, `input` and `output` may be prefixed by one of the following,
66-
* separated by the "of" keyword:
65+
* For summaries, `input` and `output` may be suffixed by any number of the
66+
* following, separated by ".":
6767
* - "Element": Selects an element in a collection.
6868
* - "Field[f]": Selects the contents of field `f`.
6969
* - "Property[p]": Selects the contents of property `p`.

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@
5454
* return value. The return values are zero-indexed
5555
* - "ReturnValue[n1..n2]": Similar to "ReturnValue[n]" but selects any
5656
* return value in the given range. The range is inclusive at both ends.
57+
*
58+
* For summaries, `input` and `output` may be suffixed by any number of the
59+
* following, separated by ".":
60+
* - "Field[pkg.className.fieldname]": Selects the contents of the field `f`
61+
* which satisfies `f.hasQualifiedName(pkg, className, fieldname)`.
62+
* - "SyntheticField[f]": Selects the contents of the synthetic field `f`.
63+
* - "ArrayElement": Selects an element in an array or slice.
64+
* - "Element": Selects an element in a collection.
65+
* - "MapKey": Selects a key in a map.
66+
* - "MapValue": Selects a value in a map.
67+
* - "Dereference": Selects the value referenced by a pointer.
68+
*
5769
* 8. The `kind` column is a tag that can be referenced from QL to determine to
5870
* which classes the interpreted elements should be added. For example, for
5971
* sources "remote" indicates a default remote flow source, and for summaries
@@ -342,6 +354,8 @@ predicate parseContent(string component, DataFlow::Content content) {
342354
component = "MapKey" and content instanceof DataFlow::MapKeyContent
343355
or
344356
component = "MapValue" and content instanceof DataFlow::MapValueContent
357+
or
358+
component = "Dereference" and content instanceof DataFlow::PointerContent
345359
}
346360

347361
cached

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ private string getContentSpecific(Content c) {
106106
c instanceof MapKeyContent and result = "MapKey"
107107
or
108108
c instanceof MapValueContent and result = "MapValue"
109+
or
110+
c instanceof PointerContent and result = "Dereference"
109111
}
110112

111113
/** Gets the textual representation of the content in the format used for flow summaries. */

go/ql/test/library-tests/semmle/go/dataflow/ExternalFlow/completetest.ext.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ extensions:
2222
- ["github.com/nonexistent/test", "", False, "GetMapKey", "", "", "Argument[0].MapKey", "ReturnValue", "value", "manual"]
2323
- ["github.com/nonexistent/test", "", False, "SetElement", "", "", "Argument[0]", "ReturnValue.Element", "value", "manual"]
2424
- ["github.com/nonexistent/test", "C", False, "Get", "", "", "Argument[-1].Field[github.com/nonexistent/test.C.F]", "ReturnValue", "value", "manual"]
25-
- ["github.com/nonexistent/test", "C", False, "GetThroughPointer", "", "", "Argument[-1].Field[github.com/nonexistent/test.C.F]", "ReturnValue", "value", "manual"]
25+
- ["github.com/nonexistent/test", "C", False, "GetThroughPointer", "", "", "Argument[-1].Dereference.Field[github.com/nonexistent/test.C.F]", "ReturnValue", "value", "manual"]
2626
- ["github.com/nonexistent/test", "C", False, "Set", "", "", "Argument[0]", "Argument[-1].Field[github.com/nonexistent/test.C.F]", "value", "manual"]
27-
- ["github.com/nonexistent/test", "C", False, "SetThroughPointer", "", "", "Argument[0]", "Argument[-1].Field[github.com/nonexistent/test.C.F]", "value", "manual"]
27+
- ["github.com/nonexistent/test", "C", False, "SetThroughPointer", "", "", "Argument[0]", "Argument[-1].Dereference.Field[github.com/nonexistent/test.C.F]", "value", "manual"]
2828

2929
- addsTo:
3030
pack: codeql/go-all

go/ql/test/library-tests/semmle/go/dataflow/ExternalFlow/test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ func simpleflow() {
143143

144144
cp1 := &test.C{""}
145145
cp1.SetThroughPointer(a.Src1().(string))
146-
b.Sink1(cp1.F) // $ MISSING: hasTaintFlow="selection of F"
146+
b.Sink1(cp1.F) // $ hasTaintFlow="selection of F"
147147

148148
cp2 := &test.C{a.Src1().(string)}
149-
b.Sink1(cp2.GetThroughPointer()) // $ MISSING: hasTaintFlow="call to GetThroughPointer"
149+
b.Sink1(cp2.GetThroughPointer()) // $ hasTaintFlow="call to GetThroughPointer"
150150

151151
cp3 := &test.C{""}
152152
cp3.SetThroughPointer(a.Src1().(string))

0 commit comments

Comments
 (0)