Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.1k
C++: Add Windows command line and environment models#19563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| category: feature | ||
| --- | ||
| * Added the `pCmdLine` arguments of `WinMain` and `wWinMain` as local flow sources. | ||
| * Added source models for `GetCommandLineA`, `GetCommandLineW`, `GetEnvironmentStringsA`, `GetEnvironmentStringsW`, `GetEnvironmentVariableA`, and `GetEnvironmentVariableW`. | ||
| * Added summary models for `CommandLineToArgvA` and `CommandLineToArgvW`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # partial model of windows system calls | ||
| extensions: | ||
| - addsTo: | ||
| pack: codeql/cpp-all | ||
| extensible: sourceModel | ||
| data: # namespace, type, subtypes, name, signature, ext, output, kind, provenance | ||
| # processenv.h | ||
| - ["", "", False, "GetCommandLineA", "", "", "ReturnValue[*]", "local", "manual"] | ||
| - ["", "", False, "GetCommandLineW", "", "", "ReturnValue[*]", "local", "manual"] | ||
| - ["", "", False, "GetEnvironmentStringsA", "", "", "ReturnValue[*]", "local", "manual"] | ||
| - ["", "", False, "GetEnvironmentStringsW", "", "", "ReturnValue[*]", "local", "manual"] | ||
| - ["", "", False, "GetEnvironmentVariableA", "", "", "Argument[*1]", "local", "manual"] | ||
| - ["", "", False, "GetEnvironmentVariableW", "", "", "Argument[*1]", "local", "manual"] | ||
| - addsTo: | ||
| pack: codeql/cpp-all | ||
| extensible: summaryModel | ||
| data: # namespace, type, subtypes, name, signature, ext, input, output, kind, provenance | ||
| # shellapi.h | ||
| - ["", "", False, "CommandLineToArgvA", "", "", "Argument[*0]", "ReturnValue[**]", "taint", "manual"] | ||
| - ["", "", False, "CommandLineToArgvW", "", "", "Argument[*0]", "ReturnValue[**]", "taint", "manual"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -55,7 +55,7 @@ private class LocalModelSource extends LocalFlowSource { | ||
| } | ||
| /** | ||
| * A local data flow source that the `argv` parameter to `main` or `wmain`. | ||
| * A local data flow source that is the `argv` parameter to `main` or `wmain`. | ||
| */ | ||
| private class ArgvSource extends LocalFlowSource { | ||
| ArgvSource() { | ||
| @@ -69,6 +69,21 @@ private class ArgvSource extends LocalFlowSource { | ||
| override string getSourceType() { result = "a command-line argument" } | ||
| } | ||
| /** | ||
| * A local data flow source that is the `pCmdLine` parameter to `WinMain` or `wWinMain`. | ||
| */ | ||
| private class CmdLineSource extends LocalFlowSource { | ||
| CmdLineSource() { | ||
| exists(Function main, Parameter pCmdLine | | ||
| main.hasGlobalName(["WinMain", "wWinMain"]) and | ||
| main.getParameter(2) = pCmdLine and | ||
| this.asParameter(1) = pCmdLine | ||
jketema marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ) | ||
| } | ||
| override string getSourceType() { result = "a command-line" } | ||
| } | ||
| /** | ||
| * A remote data flow source that is defined through 'models as data'. | ||
| */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| void sink(char); | ||
| void sink(char*); | ||
| int WinMain(void *hInstance, void *hPrevInstance, char *pCmdLine, int nCmdShow) { // $ ast-def=hInstance ast-def=hPrevInstance ast-def=pCmdLine ir-def=*hInstance ir-def=*hPrevInstance ir-def=*pCmdLine | ||
| sink(pCmdLine); | ||
| sink(*pCmdLine); // $ ir | ||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| | asio_streams.cpp:87:34:87:44 | read_until output argument | remote | | ||
| | test.cpp:10:10:10:18 | call to ymlSource | local | | ||
| | windows.cpp:11:15:11:29 | *call to GetCommandLineA | local | | ||
| | windows.cpp:23:17:23:38 | *call to GetEnvironmentStringsA | local | | ||
| | windows.cpp:28:36:28:38 | GetEnvironmentVariableA output argument | local | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| void sink(char); | ||
| void sink(char*); | ||
| void sink(char**); | ||
| char* GetCommandLineA(); | ||
| char** CommandLineToArgvA(char*, int*); | ||
| char* GetEnvironmentStringsA(); | ||
| int GetEnvironmentVariableA(const char*, char*, int); | ||
| void getCommandLine() { | ||
| char* cmd = GetCommandLineA(); | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe these ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. | ||
| sink(cmd); | ||
| sink(*cmd); // $ ir | ||
| int argc; | ||
| char** argv = CommandLineToArgvA(cmd, &argc); | ||
| sink(argv); | ||
| sink(argv[1]); | ||
| sink(*argv[1]); // $ ir | ||
| } | ||
| void getEnvironment() { | ||
| char* env = GetEnvironmentStringsA(); | ||
| sink(env); | ||
| sink(*env); // $ ir | ||
| char buf[1024]; | ||
| GetEnvironmentVariableA("FOO", buf, sizeof(buf)); | ||
| sink(buf); | ||
| sink(*buf); // $ ir | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Acknowledging I saw this. Will fix this in a separate PR.