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

Commit 8eeb019

Browse files
committed
Move existing OS (all caps name) module classes to stdlib.Os module (notice the camelcase name)
1 parent f811dff commit 8eeb019

File tree

2 files changed

+60
-81
lines changed

2 files changed

+60
-81
lines changed

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

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -395,87 +395,6 @@ module IoUtil {
395395
}
396396
}
397397

398-
/** Provides models of commonly used functions in the `os` package. */
399-
module OS {
400-
/**
401-
* A call to a function in `os` that accesses the file system.
402-
*/
403-
private class OsFileSystemAccess extends FileSystemAccess::Range, DataFlow::CallNode {
404-
int pathidx;
405-
406-
OsFileSystemAccess() {
407-
exists(string fn | getTarget().hasQualifiedName("os", fn) |
408-
fn = "Chdir" and pathidx = 0
409-
or
410-
fn = "Chmod" and pathidx = 0
411-
or
412-
fn = "Chown" and pathidx = 0
413-
or
414-
fn = "Chtimes" and pathidx = 0
415-
or
416-
fn = "Create" and pathidx = 0
417-
or
418-
fn = "Lchown" and pathidx = 0
419-
or
420-
fn = "Link" and pathidx in [0 .. 1]
421-
or
422-
fn = "Lstat" and pathidx = 0
423-
or
424-
fn = "Mkdir" and pathidx = 0
425-
or
426-
fn = "MkdirAll" and pathidx = 0
427-
or
428-
fn = "NewFile" and pathidx = 1
429-
or
430-
fn = "Open" and pathidx = 0
431-
or
432-
fn = "OpenFile" and pathidx = 0
433-
or
434-
fn = "Readlink" and pathidx = 0
435-
or
436-
fn = "Remove" and pathidx = 0
437-
or
438-
fn = "RemoveAll" and pathidx = 0
439-
or
440-
fn = "Rename" and pathidx in [0 .. 1]
441-
or
442-
fn = "Stat" and pathidx = 0
443-
or
444-
fn = "Symlink" and pathidx in [0 .. 1]
445-
or
446-
fn = "Truncate" and pathidx = 0
447-
)
448-
}
449-
450-
override DataFlow::Node getAPathArgument() { result = getArgument(pathidx) }
451-
}
452-
453-
/** The `Expand` function. */
454-
class Expand extends TaintTracking::FunctionModel {
455-
Expand() { hasQualifiedName("os", "Expand") }
456-
457-
override predicate hasTaintFlow(FunctionInput inp, FunctionOutput outp) {
458-
inp.isParameter(0) and outp.isResult()
459-
}
460-
}
461-
462-
/** The `ExpandEnv` function. */
463-
class ExpandEnv extends TaintTracking::FunctionModel {
464-
ExpandEnv() { hasQualifiedName("os", "ExpandEnv") }
465-
466-
override predicate hasTaintFlow(FunctionInput inp, FunctionOutput outp) {
467-
inp.isParameter(0) and outp.isResult()
468-
}
469-
}
470-
471-
/** The `os.Exit` function, which ends the process. */
472-
private class Exit extends Function {
473-
Exit() { hasQualifiedName("os", "Exit") }
474-
475-
override predicate mayReturnNormally() { none() }
476-
}
477-
}
478-
479398
/** Provides a class for modeling functions which convert strings into integers. */
480399
module IntegerParser {
481400
/**

ql/src/semmle/go/frameworks/stdlib/Os.qll

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,66 @@ import go
66

77
/** Provides models of commonly used functions in the `os` package. */
88
module Os {
9+
/**
10+
* A call to a function in `os` that accesses the file system.
11+
*/
12+
private class OsFileSystemAccess extends FileSystemAccess::Range, DataFlow::CallNode {
13+
int pathidx;
14+
15+
OsFileSystemAccess() {
16+
exists(string fn | getTarget().hasQualifiedName("os", fn) |
17+
fn = "Chdir" and pathidx = 0
18+
or
19+
fn = "Chmod" and pathidx = 0
20+
or
21+
fn = "Chown" and pathidx = 0
22+
or
23+
fn = "Chtimes" and pathidx = 0
24+
or
25+
fn = "Create" and pathidx = 0
26+
or
27+
fn = "Lchown" and pathidx = 0
28+
or
29+
fn = "Link" and pathidx in [0 .. 1]
30+
or
31+
fn = "Lstat" and pathidx = 0
32+
or
33+
fn = "Mkdir" and pathidx = 0
34+
or
35+
fn = "MkdirAll" and pathidx = 0
36+
or
37+
fn = "NewFile" and pathidx = 1
38+
or
39+
fn = "Open" and pathidx = 0
40+
or
41+
fn = "OpenFile" and pathidx = 0
42+
or
43+
fn = "Readlink" and pathidx = 0
44+
or
45+
fn = "Remove" and pathidx = 0
46+
or
47+
fn = "RemoveAll" and pathidx = 0
48+
or
49+
fn = "Rename" and pathidx in [0 .. 1]
50+
or
51+
fn = "Stat" and pathidx = 0
52+
or
53+
fn = "Symlink" and pathidx in [0 .. 1]
54+
or
55+
fn = "Truncate" and pathidx = 0
56+
)
57+
}
58+
59+
override DataFlow::Node getAPathArgument() { result = getArgument(pathidx) }
60+
}
61+
62+
/** The `os.Exit` function, which ends the process. */
63+
private class Exit extends Function {
64+
Exit() { hasQualifiedName("os", "Exit") }
65+
66+
override predicate mayReturnNormally() { none() }
67+
}
68+
969
private class FunctionModels extends TaintTracking::FunctionModel {
1070
FunctionInput inp;
1171
FunctionOutput outp;

0 commit comments

Comments
 (0)