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

Commit 9d13813

Browse files
committed
Merge branch 'standard-lib-pt-23' into from-331-to-337
2 parents 1d13ca5 + 6bbe018 commit 9d13813

File tree

4 files changed

+188
-0
lines changed

4 files changed

+188
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import semmle.go.frameworks.stdlib.Strconv
3737
import semmle.go.frameworks.stdlib.Strings
3838
import semmle.go.frameworks.stdlib.Sync
3939
import semmle.go.frameworks.stdlib.SyncAtomic
40+
import semmle.go.frameworks.stdlib.Syscall
4041
import semmle.go.frameworks.stdlib.TextScanner
4142
import semmle.go.frameworks.stdlib.TextTabwriter
4243
import semmle.go.frameworks.stdlib.TextTemplate
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `syscall` package.
3+
*/
4+
5+
import go
6+
7+
/** Provides models of commonly used functions in the `syscall` package. */
8+
module Syscall {
9+
private class FunctionModels extends TaintTracking::FunctionModel {
10+
FunctionInput inp;
11+
FunctionOutput outp;
12+
13+
FunctionModels() {
14+
// signature: func BytePtrFromString(s string) (*byte, error)
15+
hasQualifiedName("syscall", "BytePtrFromString") and
16+
(inp.isParameter(0) and outp.isResult(0))
17+
or
18+
// signature: func ByteSliceFromString(s string) ([]byte, error)
19+
hasQualifiedName("syscall", "ByteSliceFromString") and
20+
(inp.isParameter(0) and outp.isResult(0))
21+
or
22+
// signature: func StringBytePtr(s string) *byte
23+
hasQualifiedName("syscall", "StringBytePtr") and
24+
(inp.isParameter(0) and outp.isResult())
25+
or
26+
// signature: func StringByteSlice(s string) []byte
27+
hasQualifiedName("syscall", "StringByteSlice") and
28+
(inp.isParameter(0) and outp.isResult())
29+
or
30+
// signature: func StringSlicePtr(ss []string) []*byte
31+
hasQualifiedName("syscall", "StringSlicePtr") and
32+
(inp.isParameter(0) and outp.isResult())
33+
}
34+
35+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
36+
input = inp and output = outp
37+
}
38+
}
39+
40+
private class MethodModels extends TaintTracking::FunctionModel, Method {
41+
FunctionInput inp;
42+
FunctionOutput outp;
43+
44+
MethodModels() {
45+
// signature: func (RawConn).Read(f func(fd uintptr) (done bool)) error
46+
this.implements("syscall", "RawConn", "Read") and
47+
(inp.isReceiver() and outp.isParameter(0))
48+
or
49+
// signature: func (Conn).SyscallConn() (RawConn, error)
50+
this.implements("syscall", "Conn", "SyscallConn") and
51+
(
52+
inp.isReceiver() and outp.isResult(0)
53+
or
54+
inp.isResult(0) and outp.isReceiver()
55+
)
56+
or
57+
// signature: func (RawConn).Write(f func(fd uintptr) (done bool)) error
58+
this.implements("syscall", "RawConn", "Write") and
59+
(inp.isParameter(0) and outp.isReceiver())
60+
}
61+
62+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
63+
input = inp and output = outp
64+
}
65+
}
66+
}

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

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

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

Lines changed: 21 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)