Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 4086948

Browse files
committed
Extend context models to cover its old golang.org/x/net/context home.
1 parent b370a86 commit 4086948

File tree

6 files changed

+139
-5
lines changed

6 files changed

+139
-5
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* Added support for the `golang.org/x/net/context` package, which was already supported under its modern standard-library name `context`.

ql/src/semmle/go/frameworks/stdlib/Context.qll

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,33 @@ import go
66

77
/** Provides models of commonly used functions in the `context` package. */
88
module Context {
9+
/**
10+
* Gets the package name `context` or `golang.org/x/net/context`.
11+
*
12+
* The two packages are identical; before Go 1.7 it was only available
13+
* under `golang.org/x`; as of Go 1.7 it is included in the standard library.
14+
*/
15+
private string packagePath() { result = ["context", "golang.org/x/net/context"] }
16+
917
private class FunctionModels extends TaintTracking::FunctionModel {
1018
FunctionInput inp;
1119
FunctionOutput outp;
1220

1321
FunctionModels() {
1422
// signature: func WithCancel(parent Context) (ctx Context, cancel CancelFunc)
15-
hasQualifiedName("context", "WithCancel") and
23+
hasQualifiedName(packagePath(), "WithCancel") and
1624
(inp.isParameter(0) and outp.isResult(0))
1725
or
1826
// signature: func WithDeadline(parent Context, d time.Time) (Context, CancelFunc)
19-
hasQualifiedName("context", "WithDeadline") and
27+
hasQualifiedName(packagePath(), "WithDeadline") and
2028
(inp.isParameter(0) and outp.isResult(0))
2129
or
2230
// signature: func WithTimeout(parent Context, timeout time.Duration) (Context, CancelFunc)
23-
hasQualifiedName("context", "WithTimeout") and
31+
hasQualifiedName(packagePath(), "WithTimeout") and
2432
(inp.isParameter(0) and outp.isResult(0))
2533
or
2634
// signature: func WithValue(parent Context, key interface{}, val interface{}) Context
27-
hasQualifiedName("context", "WithValue") and
35+
hasQualifiedName(packagePath(), "WithValue") and
2836
(inp.isParameter(_) and outp.isResult())
2937
}
3038

@@ -39,7 +47,7 @@ module Context {
3947

4048
MethodModels() {
4149
// signature: func (Context).Value(key interface{}) interface{}
42-
implements("context", "Context", "Value") and
50+
implements(packagePath(), "Context", "Value") and
4351
(inp.isReceiver() and outp.isResult())
4452
}
4553

ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/Context.go

Lines changed: 78 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module example.com/m
2+
3+
go 1.14
4+
5+
require (
6+
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb
7+
)

ql/test/library-tests/semmle/go/frameworks/StdlibTaintFlow/vendor/golang.org/x/net/context/stub.go

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# golang.org/x/net v0.0.0-20201010224723-4f7140c49acb
2+
## explicit
3+
golang.org/x/net

0 commit comments

Comments
 (0)