Skip to content

Commit fdff209

Browse files
authored
Merge pull request github#17505 from owen-mc/go/inheritance-tests
Go: Add tests for model inheritance and fix bug in promoted methods
2 parents 8e85f24 + ea4f9ca commit fdff209

File tree

58 files changed

+1100
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1100
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* A method in the method set of an embedded field of a struct should not be promoted to the method set of the struct if the struct has a method with the same name. This was not being enforced, which meant that there were two methods with the same qualified name, and models were sometimes being applied when they shouldn't have been. This has now been fixed.

go/ql/lib/semmle/go/Types.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ class NamedType extends @namedtype, CompositeType {
10111011
s.hasOwnField(_, _, embedded, true) and
10121012
// ensure `m` can be promoted
10131013
not s.hasOwnField(_, m, _, _) and
1014-
not exists(Method m2 | m2.getReceiverType() = this and m2.getName() = m)
1014+
not exists(Method m2 | m2.getReceiverBaseType() = this and m2.getName() = m)
10151015
|
10161016
// If S contains an embedded field T, the method set of S includes promoted methods with receiver T
10171017
result = embedded.getMethod(m)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module semmle.go.Packages
2+
3+
go 1.21
4+
5+
require github.com/nonexistent/test v0.0.0-20200203000000-0000000000000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
testFailures
2+
invalidModelRow
3+
failures
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/go-all
4+
extensible: sourceModel
5+
data:
6+
- ["github.com/nonexistent/test", "IEmbedI1", True, "Source", "", "", "ReturnValue", "remote", "manual"]
7+
- addsTo:
8+
pack: codeql/go-all
9+
extensible: summaryModel
10+
data:
11+
- ["github.com/nonexistent/test", "IEmbedI1", True, "Step", "", "", "Argument[0]", "ReturnValue", "value", "manual"]
12+
- addsTo:
13+
pack: codeql/go-all
14+
extensible: sinkModel
15+
data:
16+
- ["github.com/nonexistent/test", "IEmbedI1", True, "Sink", "", "", "Argument[0]", "path-injection", "manual"]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import go
2+
import semmle.go.dataflow.ExternalFlow
3+
import ModelValidation
4+
import semmle.go.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
5+
import TestUtilities.InlineExpectationsTest
6+
import MakeTest<FlowTest>
7+
8+
module Config implements DataFlow::ConfigSig {
9+
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
10+
11+
predicate isSink(DataFlow::Node sink) { sink = any(FileSystemAccess fsa).getAPathArgument() }
12+
}
13+
14+
module Flow = TaintTracking::Global<Config>;
15+
16+
module FlowTest implements TestSig {
17+
string getARelevantTag() { result = "IEmbedI1[t]" }
18+
19+
predicate hasActualResult(Location location, string element, string tag, string value) {
20+
tag = "IEmbedI1[t]" and
21+
exists(DataFlow::Node sink | Flow::flowTo(sink) |
22+
sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(),
23+
location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and
24+
element = sink.toString() and
25+
value = ""
26+
)
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
testFailures
2+
invalidModelRow
3+
failures
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/go-all
4+
extensible: sourceModel
5+
data:
6+
- ["github.com/nonexistent/test", "IEmbedI2", True, "Source", "", "", "ReturnValue", "remote", "manual"]
7+
- addsTo:
8+
pack: codeql/go-all
9+
extensible: summaryModel
10+
data:
11+
- ["github.com/nonexistent/test", "IEmbedI2", True, "Step", "", "", "Argument[0]", "ReturnValue", "value", "manual"]
12+
- addsTo:
13+
pack: codeql/go-all
14+
extensible: sinkModel
15+
data:
16+
- ["github.com/nonexistent/test", "IEmbedI2", True, "Sink", "", "", "Argument[0]", "path-injection", "manual"]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import go
2+
import semmle.go.dataflow.ExternalFlow
3+
import ModelValidation
4+
import semmle.go.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
5+
import TestUtilities.InlineExpectationsTest
6+
import MakeTest<FlowTest>
7+
8+
module Config implements DataFlow::ConfigSig {
9+
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
10+
11+
predicate isSink(DataFlow::Node sink) { sink = any(FileSystemAccess fsa).getAPathArgument() }
12+
}
13+
14+
module Flow = TaintTracking::Global<Config>;
15+
16+
module FlowTest implements TestSig {
17+
string getARelevantTag() { result = "IEmbedI2[t]" }
18+
19+
predicate hasActualResult(Location location, string element, string tag, string value) {
20+
tag = "IEmbedI2[t]" and
21+
exists(DataFlow::Node sink | Flow::flowTo(sink) |
22+
sink.hasLocationInfo(location.getFile().getAbsolutePath(), location.getStartLine(),
23+
location.getStartColumn(), location.getEndLine(), location.getEndColumn()) and
24+
element = sink.toString() and
25+
value = ""
26+
)
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
testFailures
2+
invalidModelRow
3+
failures

0 commit comments

Comments
 (0)