-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
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 |
---|---|---|
@@ -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(); | ||
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 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.