Skip to content

Commit a77ddd7

Browse files
committed
C++: Add Windows command line and environment models
1 parent b800040 commit a77ddd7

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

cpp/ql/lib/ext/Windows.model.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# partial model of windows system calls
2+
extensions:
3+
- addsTo:
4+
pack: codeql/cpp-all
5+
extensible: sourceModel
6+
data: # namespace, type, subtypes, name, signature, ext, output, kind, provenance
7+
# processenv.h
8+
- ["", "", False, "GetCommandLineA", "", "", "ReturnValue[*]", "local", "manual"]
9+
- ["", "", False, "GetCommandLineW", "", "", "ReturnValue[*]", "local", "manual"]
10+
- ["", "", False, "GetEnvironmentStringsA", "", "", "ReturnValue[*]", "local", "manual"]
11+
- ["", "", False, "GetEnvironmentStringsW", "", "", "ReturnValue[*]", "local", "manual"]
12+
- ["", "", False, "GetEnvironmentVariableA", "", "", "Argument[*1]", "local", "manual"]
13+
- ["", "", False, "GetEnvironmentVariableW", "", "", "Argument[*1]", "local", "manual"]
14+
- addsTo:
15+
pack: codeql/cpp-all
16+
extensible: summaryModel
17+
data: # namespace, type, subtypes, name, signature, ext, input, output, kind, provenance
18+
# shellapi.h
19+
- ["", "", False, "CommandLineToArgvA", "", "", "Argument[*0]", "ReturnValue[**]", "taint", "manual"]
20+
- ["", "", False, "CommandLineToArgvW", "", "", "Argument[*0]", "ReturnValue[**]", "taint", "manual"]

cpp/ql/lib/semmle/code/cpp/security/FlowSources.qll

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private class LocalModelSource extends LocalFlowSource {
5555
}
5656

5757
/**
58-
* A local data flow source that the `argv` parameter to `main` or `wmain`.
58+
* A local data flow source that is the `argv` parameter to `main` or `wmain`.
5959
*/
6060
private class ArgvSource extends LocalFlowSource {
6161
ArgvSource() {
@@ -69,6 +69,21 @@ private class ArgvSource extends LocalFlowSource {
6969
override string getSourceType() { result = "a command-line argument" }
7070
}
7171

72+
/**
73+
* A local data flow source that is the `pCmdLine` parameter to `WinMain` or `wWinMain`.
74+
*/
75+
private class CmdLineSource extends LocalFlowSource {
76+
CmdLineSource() {
77+
exists(Function main, Parameter pCmdLine |
78+
main.hasGlobalName(["WinMain", "wWinMain"]) and
79+
main.getParameter(2) = pCmdLine and
80+
this.asParameter(1) = pCmdLine
81+
)
82+
}
83+
84+
override string getSourceType() { result = "a command-line" }
85+
}
86+
7287
/**
7388
* A remote data flow source that is defined through 'models as data'.
7489
*/

0 commit comments

Comments
 (0)