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

Commit be64f3e

Browse files
authored
Merge pull request #316 from gagliardetto/standard-lib-pt-17
Move `path` and `path/filepath` packages to stdlib
2 parents 976151c + 386005d commit be64f3e

File tree

5 files changed

+389
-52
lines changed

5 files changed

+389
-52
lines changed

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

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import semmle.go.frameworks.stdlib.CompressFlate
1212
import semmle.go.frameworks.stdlib.CompressGzip
1313
import semmle.go.frameworks.stdlib.CompressLzw
1414
import semmle.go.frameworks.stdlib.CompressZlib
15+
import semmle.go.frameworks.stdlib.Path
16+
import semmle.go.frameworks.stdlib.PathFilepath
1517

1618
/** A `String()` method. */
1719
class StringMethod extends TaintTracking::FunctionModel, Method {
@@ -50,36 +52,6 @@ private class CopyFunction extends TaintTracking::FunctionModel {
5052
}
5153
}
5254

53-
/** Provides models of commonly used functions in the `path/filepath` package. */
54-
module PathFilePath {
55-
/** A path-manipulating function in the `path/filepath` package. */
56-
private class PathManipulatingFunction extends TaintTracking::FunctionModel {
57-
PathManipulatingFunction() {
58-
exists(string fn | hasQualifiedName("path/filepath", fn) |
59-
fn = "Abs" or
60-
fn = "Base" or
61-
fn = "Clean" or
62-
fn = "Dir" or
63-
fn = "EvalSymlinks" or
64-
fn = "Ext" or
65-
fn = "FromSlash" or
66-
fn = "Glob" or
67-
fn = "Join" or
68-
fn = "Rel" or
69-
fn = "Split" or
70-
fn = "SplitList" or
71-
fn = "ToSlash" or
72-
fn = "VolumeName"
73-
)
74-
}
75-
76-
override predicate hasTaintFlow(FunctionInput inp, FunctionOutput outp) {
77-
inp.isParameter(_) and
78-
outp.isResult(_)
79-
}
80-
}
81-
}
82-
8355
/** Provides models of commonly used functions in the `fmt` package. */
8456
module Fmt {
8557
/** The `Sprint` function or one of its variants. */
@@ -490,28 +462,6 @@ module OS {
490462
}
491463
}
492464

493-
/** Provides models of commonly used functions in the `path` package. */
494-
module Path {
495-
/** A path-manipulating function in the `path` package. */
496-
class PathManipulatingFunction extends TaintTracking::FunctionModel {
497-
PathManipulatingFunction() {
498-
exists(string fn | hasQualifiedName("path", fn) |
499-
fn = "Base" or
500-
fn = "Clean" or
501-
fn = "Dir" or
502-
fn = "Ext" or
503-
fn = "Join" or
504-
fn = "Split"
505-
)
506-
}
507-
508-
override predicate hasTaintFlow(FunctionInput inp, FunctionOutput outp) {
509-
inp.isParameter(_) and
510-
outp.isResult(_)
511-
}
512-
}
513-
}
514-
515465
/** Provides a class for modeling functions which convert strings into integers. */
516466
module IntegerParser {
517467
/**
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `path` package.
3+
*/
4+
5+
import go
6+
7+
/** Provides models of commonly used functions in the `path` package. */
8+
module Path {
9+
private class FunctionModels extends TaintTracking::FunctionModel {
10+
FunctionInput inp;
11+
FunctionOutput outp;
12+
13+
FunctionModels() {
14+
// signature: func Base(path string) string
15+
hasQualifiedName("path", "Base") and
16+
(inp.isParameter(0) and outp.isResult())
17+
or
18+
// signature: func Clean(path string) string
19+
hasQualifiedName("path", "Clean") and
20+
(inp.isParameter(0) and outp.isResult())
21+
or
22+
// signature: func Dir(path string) string
23+
hasQualifiedName("path", "Dir") and
24+
(inp.isParameter(0) and outp.isResult())
25+
or
26+
// signature: func Ext(path string) string
27+
hasQualifiedName("path", "Ext") and
28+
(inp.isParameter(0) and outp.isResult())
29+
or
30+
// signature: func Join(elem ...string) string
31+
hasQualifiedName("path", "Join") and
32+
(inp.isParameter(_) and outp.isResult())
33+
or
34+
// signature: func Split(path string) (dir string, file string)
35+
hasQualifiedName("path", "Split") and
36+
(inp.isParameter(0) and outp.isResult(_))
37+
}
38+
39+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
40+
input = inp and output = outp
41+
}
42+
}
43+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* Provides classes modeling security-relevant aspects of the `path/filepath` package.
3+
*/
4+
5+
import go
6+
7+
/** Provides models of commonly used functions in the `path/filepath` package. */
8+
module PathFilepath {
9+
private class FunctionModels extends TaintTracking::FunctionModel {
10+
FunctionInput inp;
11+
FunctionOutput outp;
12+
13+
FunctionModels() {
14+
// signature: func Abs(path string) (string, error)
15+
hasQualifiedName("path/filepath", "Abs") and
16+
(inp.isParameter(0) and outp.isResult(0))
17+
or
18+
// signature: func Base(path string) string
19+
hasQualifiedName("path/filepath", "Base") and
20+
(inp.isParameter(0) and outp.isResult())
21+
or
22+
// signature: func Clean(path string) string
23+
hasQualifiedName("path/filepath", "Clean") and
24+
(inp.isParameter(0) and outp.isResult())
25+
or
26+
// signature: func Dir(path string) string
27+
hasQualifiedName("path/filepath", "Dir") and
28+
(inp.isParameter(0) and outp.isResult())
29+
or
30+
// signature: func EvalSymlinks(path string) (string, error)
31+
hasQualifiedName("path/filepath", "EvalSymlinks") and
32+
(inp.isParameter(0) and outp.isResult(0))
33+
or
34+
// signature: func Ext(path string) string
35+
hasQualifiedName("path/filepath", "Ext") and
36+
(inp.isParameter(0) and outp.isResult())
37+
or
38+
// signature: func FromSlash(path string) string
39+
hasQualifiedName("path/filepath", "FromSlash") and
40+
(inp.isParameter(0) and outp.isResult())
41+
or
42+
// signature: func Glob(pattern string) (matches []string, err error)
43+
hasQualifiedName("path/filepath", "Glob") and
44+
(inp.isParameter(0) and outp.isResult(0))
45+
or
46+
// signature: func Join(elem ...string) string
47+
hasQualifiedName("path/filepath", "Join") and
48+
(inp.isParameter(_) and outp.isResult())
49+
or
50+
// signature: func Rel(basepath string, targpath string) (string, error)
51+
hasQualifiedName("path/filepath", "Rel") and
52+
(inp.isParameter(_) and outp.isResult(0))
53+
or
54+
// signature: func Split(path string) (dir string, file string)
55+
hasQualifiedName("path/filepath", "Split") and
56+
(inp.isParameter(0) and outp.isResult(_))
57+
or
58+
// signature: func SplitList(path string) []string
59+
hasQualifiedName("path/filepath", "SplitList") and
60+
(inp.isParameter(0) and outp.isResult())
61+
or
62+
// signature: func ToSlash(path string) string
63+
hasQualifiedName("path/filepath", "ToSlash") and
64+
(inp.isParameter(0) and outp.isResult())
65+
or
66+
// signature: func VolumeName(path string) string
67+
hasQualifiedName("path/filepath", "VolumeName") and
68+
(inp.isParameter(0) and outp.isResult())
69+
}
70+
71+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
72+
input = inp and output = outp
73+
}
74+
}
75+
}

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

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