Skip to content

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

Merged
merged 4 commits into from
May 27, 2025

Conversation

jketema
Copy link
Contributor

@jketema jketema commented May 22, 2025

New results in DCA look genuine.

@jketema jketema force-pushed the jketema/win-flow branch from 2ab88c1 to 10f6e1c Compare May 23, 2025 17:17
@jketema jketema changed the title C++: Add Windows command line models C++: Add Windows command line environment models May 23, 2025
@jketema jketema marked this pull request as ready for review May 23, 2025 18:52
@Copilot Copilot AI review requested due to automatic review settings May 23, 2025 18:52
@jketema jketema requested a review from a team as a code owner May 23, 2025 18:52
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds Windows command-line and environment models to the C++ dataflow tests and core library, enabling flow-tracking for WinMain parameters and Win32 API calls.

  • Introduce windows.cpp and winmain.cpp tests covering GetCommandLineA/W, CommandLineToArgvA/W, GetEnvironmentStringsA/W, GetEnvironmentVariableA/W, and WinMain’s pCmdLine.
  • Update expected .expected files to include new source, step, flow, and irFlow entries for those tests.
  • Add a CmdLineSource in FlowSources.qll, import it in TestBase.qll, and define YML models in Windows.model.yml; document the change in change-notes.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cpp/ql/test/library-tests/dataflow/external-models/windows.cpp New tests exercising Windows command-line & env APIs
cpp/ql/test/library-tests/dataflow/dataflow-tests/winmain.cpp New WinMain test for pCmdLine source
cpp/ql/test/library-tests/dataflow/external-models/steps.expected Updated step expectations for CommandLineToArgvA
cpp/ql/test/library-tests/dataflow/external-models/sources.expected Added sources for Win32 APIs
cpp/ql/test/library-tests/dataflow/external-models/flow.expected Added flow edges for Windows external models
cpp/ql/test/library-tests/dataflow/dataflow-tests/test-source-sink.expected Added WinMain irFlow entry
cpp/ql/test/library-tests/dataflow/dataflow-tests/TestBase.qll Imported new FlowSources and extended isSource
cpp/ql/lib/semmle/code/cpp/security/FlowSources.qll Added CmdLineSource model for WinMain’s pCmdLine
cpp/ql/lib/ext/Windows.model.yml Defined summary/source models for Win32 APIs
cpp/ql/lib/change-notes/2025-05-23-windows-sources.md Documented the new Windows sources and models
Comments suppressed due to low confidence (1)

cpp/ql/test/library-tests/dataflow/external-models/steps.expected:8

  • The table entry refers to *cmd at column 16:36–16:38, but the dereference in the code is *argv[1]. This should be updated to reference *argv[1] to match the actual code under test.
| windows.cpp:16:36:16:38 | *cmd | windows.cpp:16:17:16:34 | **call to CommandLineToArgvA |

@jketema jketema changed the title C++: Add Windows command line environment models C++: Add Windows command line and environment models May 23, 2025
Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@@ -0,0 +1,20 @@
# partial model of windows system calls
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# partial model of windows system calls
# partial model of windows system calls

Copy link
Contributor Author

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.

int GetEnvironmentVariableA(const char*, char*, int);

void getCommandLine() {
char* cmd = GetCommandLineA();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these A and W variants are often called via a macro with no letter (in this case it would be GetCommandLine). It's probably fine that we test on the specific implementation functions and I suspect many users do in fact call them directly as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.

@jketema jketema merged commit b071a46 into github:main May 27, 2025
16 checks passed
@jketema jketema deleted the jketema/win-flow branch May 27, 2025 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants