From a77ddd7532e935720a9ccb9b38d30e7033b50d6a Mon Sep 17 00:00:00 2001 From: Jeroen Ketema Date: Thu, 22 May 2025 20:26:01 +0200 Subject: [PATCH] C++: Add Windows command line and environment models --- cpp/ql/lib/ext/Windows.model.yml | 20 +++++++++++++++++++ .../semmle/code/cpp/security/FlowSources.qll | 17 +++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 cpp/ql/lib/ext/Windows.model.yml diff --git a/cpp/ql/lib/ext/Windows.model.yml b/cpp/ql/lib/ext/Windows.model.yml new file mode 100644 index 00000000000..acac5f5fbf8 --- /dev/null +++ b/cpp/ql/lib/ext/Windows.model.yml @@ -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"] diff --git a/cpp/ql/lib/semmle/code/cpp/security/FlowSources.qll b/cpp/ql/lib/semmle/code/cpp/security/FlowSources.qll index b5e94d4c046..eba6f9339ff 100644 --- a/cpp/ql/lib/semmle/code/cpp/security/FlowSources.qll +++ b/cpp/ql/lib/semmle/code/cpp/security/FlowSources.qll @@ -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 + ) + } + + override string getSourceType() { result = "a command-line" } +} + /** * A remote data flow source that is defined through 'models as data'. */