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

Commit 073fae9

Browse files
committed
Move to stdlib and extend the module for io/ioutil package
1 parent 45dfc2b commit 073fae9

File tree

3 files changed

+101
-29
lines changed

3 files changed

+101
-29
lines changed

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -146,35 +146,6 @@ module Fmt {
146146
}
147147
}
148148

149-
/** Provides models of commonly used functions in the `io/ioutil` package. */
150-
module IoUtil {
151-
private class IoUtilFileSystemAccess extends FileSystemAccess::Range, DataFlow::CallNode {
152-
IoUtilFileSystemAccess() {
153-
exists(string fn | getTarget().hasQualifiedName("io/ioutil", fn) |
154-
fn = "ReadDir" or
155-
fn = "ReadFile" or
156-
fn = "TempDir" or
157-
fn = "TempFile" or
158-
fn = "WriteFile"
159-
)
160-
}
161-
162-
override DataFlow::Node getAPathArgument() { result = getAnArgument() }
163-
}
164-
165-
/**
166-
* A taint model of the `ioutil.ReadAll` function, recording that it propagates taint
167-
* from its first argument to its first result.
168-
*/
169-
private class ReadAll extends TaintTracking::FunctionModel {
170-
ReadAll() { hasQualifiedName("io/ioutil", "ReadAll") }
171-
172-
override predicate hasTaintFlow(FunctionInput inp, FunctionOutput outp) {
173-
inp.isParameter(0) and outp.isResult(0)
174-
}
175-
}
176-
}
177-
178149
/** Provides models of commonly used functions in the `os` package. */
179150
module OS {
180151
/**
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `io/ioutil` package.
3+
*/
4+
5+
import go
6+
7+
/** Provides models of commonly used functions in the `io/ioutil` package. */
8+
module IoIoutil {
9+
private class IoUtilFileSystemAccess extends FileSystemAccess::Range, DataFlow::CallNode {
10+
IoUtilFileSystemAccess() {
11+
exists(string fn | getTarget().hasQualifiedName("io/ioutil", fn) |
12+
fn = "ReadDir" or
13+
fn = "ReadFile" or
14+
fn = "TempDir" or
15+
fn = "TempFile" or
16+
fn = "WriteFile"
17+
)
18+
}
19+
20+
override DataFlow::Node getAPathArgument() { result = getAnArgument() }
21+
}
22+
23+
private class FunctionModels extends TaintTracking::FunctionModel {
24+
FunctionInput inp;
25+
FunctionOutput outp;
26+
27+
FunctionModels() {
28+
// signature: func NopCloser(r io.Reader) io.ReadCloser
29+
hasQualifiedName("io/ioutil", "NopCloser") and
30+
(inp.isParameter(0) and outp.isResult())
31+
or
32+
// signature: func ReadAll(r io.Reader) ([]byte, error)
33+
hasQualifiedName("io/ioutil", "ReadAll") and
34+
(inp.isParameter(0) and outp.isResult(0))
35+
}
36+
37+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
38+
input = inp and output = outp
39+
}
40+
}
41+
42+
private class MethodModels extends TaintTracking::FunctionModel, Method {
43+
FunctionInput inp;
44+
FunctionOutput outp;
45+
46+
MethodModels() {
47+
// signature: func (Writer).Write(p []byte) (n int, err error)
48+
this.implements("io", "Writer", "Write") and
49+
(inp.isParameter(0) and outp.isReceiver())
50+
}
51+
52+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
53+
input = inp and output = outp
54+
}
55+
}
56+
}

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

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