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

Commit 74fdfba

Browse files
committed
Add taint-tracking for encoding/hex
1 parent 7a42992 commit 74fdfba

File tree

3 files changed

+157
-0
lines changed

3 files changed

+157
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import semmle.go.frameworks.stdlib.EncodingBase64
2323
import semmle.go.frameworks.stdlib.EncodingBinary
2424
import semmle.go.frameworks.stdlib.EncodingCsv
2525
import semmle.go.frameworks.stdlib.EncodingGob
26+
import semmle.go.frameworks.stdlib.EncodingHex
2627
import semmle.go.frameworks.stdlib.Path
2728
import semmle.go.frameworks.stdlib.PathFilepath
2829
import semmle.go.frameworks.stdlib.Reflect
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `encoding/hex` package.
3+
*/
4+
5+
import go
6+
7+
/** Provides models of commonly used functions in the `encoding/hex` package. */
8+
module EncodingHex {
9+
private class FunctionModels extends TaintTracking::FunctionModel {
10+
FunctionInput inp;
11+
FunctionOutput outp;
12+
13+
FunctionModels() {
14+
// signature: func Decode(dst []byte, src []byte) (int, error)
15+
hasQualifiedName("encoding/hex", "Decode") and
16+
(inp.isParameter(1) and outp.isParameter(0))
17+
or
18+
// signature: func DecodeString(s string) ([]byte, error)
19+
hasQualifiedName("encoding/hex", "DecodeString") and
20+
(inp.isParameter(0) and outp.isResult(0))
21+
or
22+
// signature: func Dump(data []byte) string
23+
hasQualifiedName("encoding/hex", "Dump") and
24+
(inp.isParameter(0) and outp.isResult())
25+
or
26+
// signature: func Dumper(w io.Writer) io.WriteCloser
27+
hasQualifiedName("encoding/hex", "Dumper") and
28+
(inp.isResult() and outp.isParameter(0))
29+
or
30+
// signature: func Encode(dst []byte, src []byte) int
31+
hasQualifiedName("encoding/hex", "Encode") and
32+
(inp.isParameter(1) and outp.isParameter(0))
33+
or
34+
// signature: func EncodeToString(src []byte) string
35+
hasQualifiedName("encoding/hex", "EncodeToString") and
36+
(inp.isParameter(0) and outp.isResult())
37+
or
38+
// signature: func NewDecoder(r io.Reader) io.Reader
39+
hasQualifiedName("encoding/hex", "NewDecoder") and
40+
(inp.isParameter(0) and outp.isResult())
41+
or
42+
// signature: func NewEncoder(w io.Writer) io.Writer
43+
hasQualifiedName("encoding/hex", "NewEncoder") and
44+
(inp.isResult() and outp.isParameter(0))
45+
}
46+
47+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
48+
input = inp and output = outp
49+
}
50+
}
51+
}

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

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