Skip to content

Commit 180246b

Browse files
authored
Merge pull request github#12197 from smowton/smowton/admin/go-120-features
Go: complete Go 1.20 support
2 parents 45c1537 + 3ce7faf commit 180246b

File tree

18 files changed

+387
-92
lines changed

18 files changed

+387
-92
lines changed

docs/codeql/reusables/supported-versions-compilers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
.NET Core up to 3.1
1717

1818
.NET 5, .NET 6","``.sln``, ``.csproj``, ``.cs``, ``.cshtml``, ``.xaml``"
19-
Go (aka Golang), "Go up to 1.19", "Go 1.11 or more recent", ``.go``
19+
Go (aka Golang), "Go up to 1.20", "Go 1.11 or more recent", ``.go``
2020
Java,"Java 7 to 19 [4]_","javac (OpenJDK and Oracle JDK),
2121

2222
Eclipse compiler for Java (ECJ) [5]_",``.java``
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: feature
3+
---
4+
* Go 1.20 is now supported. The extractor now functions as expected when Go 1.20 is installed, the definitions of `implementsComparable` has been updated according to Go 1.20's new, more-liberal rules, and taint flow models have been added for relevant new standard library functions.

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,10 @@ class Type extends @type {
112112
or
113113
u instanceof ArrayType and u.(ArrayType).getElementType().implementsComparable()
114114
or
115-
exists(InterfaceType uif | uif = u |
116-
not uif instanceof BasicInterfaceType and
117-
if exists(uif.getAnEmbeddedTypeSetLiteral())
118-
then
119-
// All types in the intersection of all the embedded type set
120-
// literals must implement comparable.
121-
forall(Type intersectionType |
122-
intersectionType = uif.getAnEmbeddedTypeSetLiteral().getATerm().getType() and
123-
forall(TypeSetLiteralType tslit | tslit = uif.getAnEmbeddedTypeSetLiteral() |
124-
intersectionType = tslit.getATerm().getType()
125-
)
126-
|
127-
intersectionType.implementsComparable()
128-
)
129-
else uif.isOrEmbedsComparable()
130-
)
115+
// As of Go 1.20, any interface type satisfies the `comparable` constraint, even though comparison
116+
// may panic at runtime depending on the actual object's concrete type.
117+
// Look at git history here if you need the old definition.
118+
u instanceof InterfaceType
131119
)
132120
}
133121

go/ql/lib/semmle/go/frameworks/Stdlib.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import semmle.go.frameworks.stdlib.Syscall
6565
import semmle.go.frameworks.stdlib.TextScanner
6666
import semmle.go.frameworks.stdlib.TextTabwriter
6767
import semmle.go.frameworks.stdlib.TextTemplate
68+
import semmle.go.frameworks.stdlib.Unsafe
6869

6970
/** A `String()` method. */
7071
class StringMethod extends TaintTracking::FunctionModel, Method {

go/ql/lib/semmle/go/frameworks/stdlib/Bytes.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ module Bytes {
1111
FunctionOutput outp;
1212

1313
FunctionModels() {
14+
hasQualifiedName("bytes", "Clone") and
15+
(inp.isParameter(0) and outp.isResult())
16+
or
17+
hasQualifiedName("bytes", "Cut") and
18+
(inp.isParameter(0) and outp.isResult([0, 1]))
19+
or
20+
hasQualifiedName("bytes", ["CutPrefix", "CutSuffix"]) and
21+
(inp.isParameter(0) and outp.isResult(0))
22+
or
1423
// signature: func Fields(s []byte) [][]byte
1524
hasQualifiedName("bytes", "Fields") and
1625
(inp.isParameter(0) and outp.isResult())

go/ql/lib/semmle/go/frameworks/stdlib/Errors.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ module Errors {
2222
// signature: func Unwrap(err error) error
2323
hasQualifiedName("errors", "Unwrap") and
2424
(inp.isParameter(0) and outp.isResult())
25+
or
26+
// signature: func Join(errs ...error) error
27+
hasQualifiedName("errors", "Join") and
28+
(inp.isParameter(_) and outp.isResult())
2529
}
2630

2731
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {

go/ql/lib/semmle/go/frameworks/stdlib/Sync.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ module Sync {
1111
FunctionOutput outp;
1212

1313
MethodModels() {
14+
hasQualifiedName("sync", "Map", "CompareAndSwap") and
15+
(inp.isParameter(2) and outp.isReceiver())
16+
or
1417
// signature: func (*Map) Load(key interface{}) (value interface{}, ok bool)
1518
hasQualifiedName("sync", "Map", "Load") and
1619
(inp.isReceiver() and outp.isResult(0))
@@ -28,6 +31,13 @@ module Sync {
2831
hasQualifiedName("sync", "Map", "Store") and
2932
(inp.isParameter(_) and outp.isReceiver())
3033
or
34+
hasQualifiedName("sync", "Map", "Swap") and
35+
(
36+
inp.isReceiver() and outp.isResult(0)
37+
or
38+
inp.isParameter(_) and outp.isReceiver()
39+
)
40+
or
3141
// signature: func (*Pool) Get() interface{}
3242
hasQualifiedName("sync", "Pool", "Get") and
3343
(inp.isReceiver() and outp.isResult())
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `unsafe` package.
3+
*/
4+
5+
import go
6+
7+
/** Provides models of commonly used functions in the `unsafe` package. */
8+
module Unsafe {
9+
private class FunctionModels extends TaintTracking::FunctionModel {
10+
FunctionInput inp;
11+
FunctionOutput outp;
12+
13+
FunctionModels() {
14+
hasQualifiedName("unsafe", ["String", "StringData", "Slice", "SliceData"]) and
15+
(inp.isParameter(0) and outp.isResult())
16+
}
17+
18+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
19+
input = inp and output = outp
20+
}
21+
}
22+
}

go/ql/test/library-tests/semmle/go/Types/QualifiedNames.expected

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,31 @@
5151
| interface.go:95:6:95:8 | i18 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.i18 |
5252
| interface.go:101:6:101:8 | i19 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.i19 |
5353
| interface.go:105:6:105:8 | i20 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.i20 |
54-
| interface.go:110:6:110:19 | testComparable | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable |
55-
| interface.go:111:6:111:20 | testComparable0 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable0 |
56-
| interface.go:112:6:112:20 | testComparable1 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable1 |
57-
| interface.go:113:6:113:20 | testComparable2 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable2 |
58-
| interface.go:114:6:114:20 | testComparable3 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable3 |
59-
| interface.go:115:6:115:20 | testComparable4 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable4 |
60-
| interface.go:116:6:116:20 | testComparable5 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable5 |
61-
| interface.go:117:6:117:20 | testComparable6 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable6 |
62-
| interface.go:118:6:118:20 | testComparable7 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable7 |
63-
| interface.go:119:6:119:20 | testComparable8 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable8 |
64-
| interface.go:120:6:120:20 | testComparable9 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable9 |
65-
| interface.go:121:6:121:21 | testComparable10 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable10 |
66-
| interface.go:122:6:122:21 | testComparable11 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable11 |
67-
| interface.go:123:6:123:21 | testComparable12 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable12 |
68-
| interface.go:124:6:124:21 | testComparable13 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable13 |
69-
| interface.go:125:6:125:21 | testComparable14 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable14 |
70-
| interface.go:126:6:126:21 | testComparable15 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable15 |
71-
| interface.go:127:6:127:21 | testComparable16 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable16 |
72-
| interface.go:128:6:128:21 | testComparable17 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable17 |
73-
| interface.go:129:6:129:21 | testComparable18 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable18 |
74-
| interface.go:130:6:130:21 | testComparable19 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable19 |
75-
| interface.go:131:6:131:21 | testComparable20 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable20 |
76-
| interface.go:132:6:132:21 | testComparable21 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable21 |
77-
| interface.go:133:6:133:21 | testComparable22 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable22 |
78-
| interface.go:134:6:134:21 | testComparable23 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable23 |
54+
| interface.go:114:6:114:19 | testComparable | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable |
55+
| interface.go:115:6:115:20 | testComparable0 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable0 |
56+
| interface.go:116:6:116:20 | testComparable1 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable1 |
57+
| interface.go:117:6:117:20 | testComparable2 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable2 |
58+
| interface.go:118:6:118:20 | testComparable3 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable3 |
59+
| interface.go:119:6:119:20 | testComparable4 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable4 |
60+
| interface.go:120:6:120:20 | testComparable5 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable5 |
61+
| interface.go:121:6:121:20 | testComparable6 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable6 |
62+
| interface.go:122:6:122:20 | testComparable7 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable7 |
63+
| interface.go:123:6:123:20 | testComparable8 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable8 |
64+
| interface.go:124:6:124:20 | testComparable9 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable9 |
65+
| interface.go:125:6:125:21 | testComparable10 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable10 |
66+
| interface.go:126:6:126:21 | testComparable11 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable11 |
67+
| interface.go:127:6:127:21 | testComparable12 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable12 |
68+
| interface.go:128:6:128:21 | testComparable13 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable13 |
69+
| interface.go:129:6:129:21 | testComparable14 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable14 |
70+
| interface.go:130:6:130:21 | testComparable15 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable15 |
71+
| interface.go:131:6:131:21 | testComparable16 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable16 |
72+
| interface.go:132:6:132:21 | testComparable17 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable17 |
73+
| interface.go:133:6:133:21 | testComparable18 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable18 |
74+
| interface.go:134:6:134:21 | testComparable19 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable19 |
75+
| interface.go:135:6:135:21 | testComparable20 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable20 |
76+
| interface.go:136:6:136:21 | testComparable21 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable21 |
77+
| interface.go:137:6:137:21 | testComparable22 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable22 |
78+
| interface.go:138:6:138:21 | testComparable23 | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types.testComparable23 |
7979
| pkg1/embedding.go:8:6:8:9 | base | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.base |
8080
| pkg1/embedding.go:19:6:19:13 | embedder | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.embedder |
8181
| pkg1/embedding.go:22:6:22:16 | ptrembedder | github.com/github/codeql-go/ql/test/library-tests/semmle/go/Types/pkg1.ptrembedder |

go/ql/test/library-tests/semmle/go/Types/Types.expected

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,31 @@
5151
| interface.go:95:6:95:8 | i18 | i18 |
5252
| interface.go:101:6:101:8 | i19 | i19 |
5353
| interface.go:105:6:105:8 | i20 | i20 |
54-
| interface.go:110:6:110:19 | testComparable | testComparable |
55-
| interface.go:111:6:111:20 | testComparable0 | testComparable0 |
56-
| interface.go:112:6:112:20 | testComparable1 | testComparable1 |
57-
| interface.go:113:6:113:20 | testComparable2 | testComparable2 |
58-
| interface.go:114:6:114:20 | testComparable3 | testComparable3 |
59-
| interface.go:115:6:115:20 | testComparable4 | testComparable4 |
60-
| interface.go:116:6:116:20 | testComparable5 | testComparable5 |
61-
| interface.go:117:6:117:20 | testComparable6 | testComparable6 |
62-
| interface.go:118:6:118:20 | testComparable7 | testComparable7 |
63-
| interface.go:119:6:119:20 | testComparable8 | testComparable8 |
64-
| interface.go:120:6:120:20 | testComparable9 | testComparable9 |
65-
| interface.go:121:6:121:21 | testComparable10 | testComparable10 |
66-
| interface.go:122:6:122:21 | testComparable11 | testComparable11 |
67-
| interface.go:123:6:123:21 | testComparable12 | testComparable12 |
68-
| interface.go:124:6:124:21 | testComparable13 | testComparable13 |
69-
| interface.go:125:6:125:21 | testComparable14 | testComparable14 |
70-
| interface.go:126:6:126:21 | testComparable15 | testComparable15 |
71-
| interface.go:127:6:127:21 | testComparable16 | testComparable16 |
72-
| interface.go:128:6:128:21 | testComparable17 | testComparable17 |
73-
| interface.go:129:6:129:21 | testComparable18 | testComparable18 |
74-
| interface.go:130:6:130:21 | testComparable19 | testComparable19 |
75-
| interface.go:131:6:131:21 | testComparable20 | testComparable20 |
76-
| interface.go:132:6:132:21 | testComparable21 | testComparable21 |
77-
| interface.go:133:6:133:21 | testComparable22 | testComparable22 |
78-
| interface.go:134:6:134:21 | testComparable23 | testComparable23 |
54+
| interface.go:114:6:114:19 | testComparable | testComparable |
55+
| interface.go:115:6:115:20 | testComparable0 | testComparable0 |
56+
| interface.go:116:6:116:20 | testComparable1 | testComparable1 |
57+
| interface.go:117:6:117:20 | testComparable2 | testComparable2 |
58+
| interface.go:118:6:118:20 | testComparable3 | testComparable3 |
59+
| interface.go:119:6:119:20 | testComparable4 | testComparable4 |
60+
| interface.go:120:6:120:20 | testComparable5 | testComparable5 |
61+
| interface.go:121:6:121:20 | testComparable6 | testComparable6 |
62+
| interface.go:122:6:122:20 | testComparable7 | testComparable7 |
63+
| interface.go:123:6:123:20 | testComparable8 | testComparable8 |
64+
| interface.go:124:6:124:20 | testComparable9 | testComparable9 |
65+
| interface.go:125:6:125:21 | testComparable10 | testComparable10 |
66+
| interface.go:126:6:126:21 | testComparable11 | testComparable11 |
67+
| interface.go:127:6:127:21 | testComparable12 | testComparable12 |
68+
| interface.go:128:6:128:21 | testComparable13 | testComparable13 |
69+
| interface.go:129:6:129:21 | testComparable14 | testComparable14 |
70+
| interface.go:130:6:130:21 | testComparable15 | testComparable15 |
71+
| interface.go:131:6:131:21 | testComparable16 | testComparable16 |
72+
| interface.go:132:6:132:21 | testComparable17 | testComparable17 |
73+
| interface.go:133:6:133:21 | testComparable18 | testComparable18 |
74+
| interface.go:134:6:134:21 | testComparable19 | testComparable19 |
75+
| interface.go:135:6:135:21 | testComparable20 | testComparable20 |
76+
| interface.go:136:6:136:21 | testComparable21 | testComparable21 |
77+
| interface.go:137:6:137:21 | testComparable22 | testComparable22 |
78+
| interface.go:138:6:138:21 | testComparable23 | testComparable23 |
7979
| pkg1/embedding.go:8:6:8:9 | base | base |
8080
| pkg1/embedding.go:19:6:19:13 | embedder | embedder |
8181
| pkg1/embedding.go:22:6:22:16 | ptrembedder | ptrembedder |

0 commit comments

Comments
 (0)