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

Commit f811dff

Browse files
committed
Add taint-tracking for package os
1 parent fee596a commit f811dff

File tree

3 files changed

+247
-0
lines changed
  • ql
    • src/semmle/go/frameworks
    • test/library-tests/semmle/go/frameworks/StdlibTaintFlow

3 files changed

+247
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import semmle.go.frameworks.stdlib.EncodingPem
2929
import semmle.go.frameworks.stdlib.EncodingXml
3030
import semmle.go.frameworks.stdlib.Html
3131
import semmle.go.frameworks.stdlib.HtmlTemplate
32+
import semmle.go.frameworks.stdlib.Os
3233
import semmle.go.frameworks.stdlib.Path
3334
import semmle.go.frameworks.stdlib.PathFilepath
3435
import semmle.go.frameworks.stdlib.Reflect
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `os` package.
3+
*/
4+
5+
import go
6+
7+
/** Provides models of commonly used functions in the `os` package. */
8+
module Os {
9+
private class FunctionModels extends TaintTracking::FunctionModel {
10+
FunctionInput inp;
11+
FunctionOutput outp;
12+
13+
FunctionModels() {
14+
// signature: func Expand(s string, mapping func(string) string) string
15+
hasQualifiedName("os", "Expand") and
16+
(inp.isParameter(0) and outp.isResult())
17+
or
18+
// signature: func ExpandEnv(s string) string
19+
hasQualifiedName("os", "ExpandEnv") and
20+
(inp.isParameter(0) and outp.isResult())
21+
or
22+
// signature: func NewFile(fd uintptr, name string) *File
23+
hasQualifiedName("os", "NewFile") and
24+
(inp.isParameter(0) and outp.isResult())
25+
or
26+
// signature: func Pipe() (r *File, w *File, err error)
27+
hasQualifiedName("os", "Pipe") and
28+
(inp.isResult(1) and outp.isResult(0))
29+
}
30+
31+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
32+
input = inp and output = outp
33+
}
34+
}
35+
36+
private class MethodModels extends TaintTracking::FunctionModel, Method {
37+
FunctionInput inp;
38+
FunctionOutput outp;
39+
40+
MethodModels() {
41+
// signature: func (*File).Fd() uintptr
42+
this.hasQualifiedName("os", "File", "Fd") and
43+
(inp.isReceiver() and outp.isResult())
44+
or
45+
// signature: func (*File).Read(b []byte) (n int, err error)
46+
this.hasQualifiedName("os", "File", "Read") and
47+
(inp.isReceiver() and outp.isParameter(0))
48+
or
49+
// signature: func (*File).ReadAt(b []byte, off int64) (n int, err error)
50+
this.hasQualifiedName("os", "File", "ReadAt") and
51+
(inp.isReceiver() and outp.isParameter(0))
52+
or
53+
// signature: func (*File).ReadFrom(r io.Reader) (n int64, err error)
54+
this.hasQualifiedName("os", "File", "ReadFrom") and
55+
(inp.isParameter(0) and outp.isReceiver())
56+
or
57+
// signature: func (*File).SyscallConn() (syscall.RawConn, error)
58+
this.hasQualifiedName("os", "File", "SyscallConn") and
59+
(
60+
inp.isReceiver() and outp.isResult(0)
61+
or
62+
inp.isResult(0) and outp.isReceiver()
63+
)
64+
or
65+
// signature: func (*File).Write(b []byte) (n int, err error)
66+
this.hasQualifiedName("os", "File", "Write") and
67+
(inp.isParameter(0) and outp.isReceiver())
68+
or
69+
// signature: func (*File).WriteAt(b []byte, off int64) (n int, err error)
70+
this.hasQualifiedName("os", "File", "WriteAt") and
71+
(inp.isParameter(0) and outp.isReceiver())
72+
or
73+
// signature: func (*File).WriteString(s string) (n int, err error)
74+
this.hasQualifiedName("os", "File", "WriteString") and
75+
(inp.isParameter(0) and outp.isReceiver())
76+
}
77+
78+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
79+
input = inp and output = outp
80+
}
81+
}
82+
}

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

Lines changed: 164 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)