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

Commit db0b09b

Browse files
committed
Add taint-tracking for text/tabwriter package.
1 parent 4df363d commit db0b09b

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import semmle.go.frameworks.stdlib.CompressZlib
1515
import semmle.go.frameworks.stdlib.Path
1616
import semmle.go.frameworks.stdlib.PathFilepath
1717
import semmle.go.frameworks.stdlib.TextScanner
18+
import semmle.go.frameworks.stdlib.TextTabwriter
1819

1920
/** A `String()` method. */
2021
class StringMethod extends TaintTracking::FunctionModel, Method {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `text/tabwriter` package.
3+
*/
4+
5+
import go
6+
7+
/** Provides models of commonly used functions in the `text/tabwriter` package. */
8+
module TextTabwriter {
9+
private class FunctionModels extends TaintTracking::FunctionModel {
10+
FunctionInput inp;
11+
FunctionOutput outp;
12+
13+
FunctionModels() {
14+
// signature: func NewWriter(output io.Writer, minwidth int, tabwidth int, padding int, padchar byte, flags uint) *Writer
15+
hasQualifiedName("text/tabwriter", "NewWriter") and
16+
(inp.isResult() and outp.isParameter(0))
17+
}
18+
19+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
20+
input = inp and output = outp
21+
}
22+
}
23+
24+
private class MethodModels extends TaintTracking::FunctionModel, Method {
25+
FunctionInput inp;
26+
FunctionOutput outp;
27+
28+
MethodModels() {
29+
// signature: func (*Writer).Init(output io.Writer, minwidth int, tabwidth int, padding int, padchar byte, flags uint) *Writer
30+
this.hasQualifiedName("text/tabwriter", "Writer", "Init") and
31+
(
32+
(inp.isReceiver() or inp.isResult()) and
33+
outp.isParameter(0)
34+
)
35+
or
36+
// signature: func (*Writer).Write(buf []byte) (n int, err error)
37+
this.hasQualifiedName("text/tabwriter", "Writer", "Write") and
38+
(inp.isParameter(0) and outp.isReceiver())
39+
}
40+
41+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
42+
input = inp and output = outp
43+
}
44+
}
45+
}

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

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