Skip to content

C++: Add Windows command line and environment models - #19563

Merged
jketema merged 4 commits into
github:mainfrom
jketema:jketema/win-flow
May 27, 2025
Merged

C++: Add Windows command line and environment models#19563
jketema merged 4 commits into
github:mainfrom
jketema:jketema/win-flow

Conversation

@jketema

@jketemajketema commented May 22, 2025

Copy link
Copy Markdown
Contributor

New results in DCA look genuine.

@jketemajketema changed the title C++: Add Windows command line modelsC++: Add Windows command line environment modelsMay 23, 2025
@jketema
jketema marked this pull request as ready for review May 23, 2025 18:52
CopilotAI review requested due to automatic review settings May 23, 2025 18:52
@jketema
jketema requested a review from a team as a code ownerMay 23, 2025 18:52

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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
FileDescription
cpp/ql/test/library-tests/dataflow/external-models/windows.cppNew tests exercising Windows command-line & env APIs
cpp/ql/test/library-tests/dataflow/dataflow-tests/winmain.cppNew WinMain test for pCmdLine source
cpp/ql/test/library-tests/dataflow/external-models/steps.expectedUpdated step expectations for CommandLineToArgvA
cpp/ql/test/library-tests/dataflow/external-models/sources.expectedAdded sources for Win32 APIs
cpp/ql/test/library-tests/dataflow/external-models/flow.expectedAdded flow edges for Windows external models
cpp/ql/test/library-tests/dataflow/dataflow-tests/test-source-sink.expectedAdded WinMain irFlow entry
cpp/ql/test/library-tests/dataflow/dataflow-tests/TestBase.qllImported new FlowSources and extended isSource
cpp/ql/lib/semmle/code/cpp/security/FlowSources.qllAdded CmdLineSource model for WinMain’s pCmdLine
cpp/ql/lib/ext/Windows.model.ymlDefined summary/source models for Win32 APIs
cpp/ql/lib/change-notes/2025-05-23-windows-sources.mdDocumented 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 |

Comment threadcpp/ql/lib/semmle/code/cpp/security/FlowSources.qll
@jketemajketema changed the title C++: Add Windows command line environment modelsC++: Add Windows command line and environment modelsMay 23, 2025

@geoffw0geoffw0 left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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:mainMay 27, 2025
@jketema
jketema deleted the jketema/win-flow branch May 27, 2025 10:32
Sign up for freeto 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.

3 participants

@jketema@geoffw0