Skip to content

C++: Add more Win32 flow sources #19591

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 5 commits into from
May 27, 2025

Conversation

MathiasVP
Copy link
Contributor

This PR adds Win32 specific flow sources related to reading/memory mapping files.

@Copilot Copilot AI review requested due to automatic review settings May 27, 2025 10:38
@MathiasVP MathiasVP requested a review from a team as a code owner May 27, 2025 10:38
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 Win32-specific dataflow tests and models for file reading and memory mapping APIs.

  • Extends windows.cpp test suite with ReadFile, ReadFileEx, NtReadFile, and various MapViewOfFile calls.
  • Updates sources.expected and flow.expected to include flows from the new APIs.
  • Adds new entries in Windows.model.yml and documents the feature in change notes.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
cpp/ql/test/library-tests/dataflow/external-models/windows.cpp Added tests for ReadFile, ReadFileEx, NtReadFile, and MapViewOfFile*
cpp/ql/test/library-tests/dataflow/external-models/sources.expected Added expected source entries for the new Win32 APIs
cpp/ql/test/library-tests/dataflow/external-models/flow.expected Updated provenance entries for the added test flows
cpp/ql/lib/ext/Windows.model.yml Defined new flow source models for ReadFile, memory mapping, and NtReadFile
cpp/ql/lib/change-notes/2025-05-27-windows-sources-2.md Documented the addition of the new flow source models
Comments suppressed due to low confidence (1)

cpp/ql/test/library-tests/dataflow/external-models/windows.cpp:158

  • [nitpick] The variable name 'p' is ambiguous; a more descriptive name like 'bufferPtr' would improve readability.
char* p = reinterpret_cast<char*>(overlapped.hEvent);

jketema
jketema previously approved these changes May 27, 2025
Copy link
Contributor

@jketema jketema left a comment

Choose a reason for hiding this comment

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

LGTM is DCA is happy. Just some minor nits about documenting where the functions are coming from.

Comment on lines +33 to +39
using HANDLE = void*;
using DWORD = unsigned long;
using LPVOID = void*;
using LPDWORD = unsigned long*;
using PVOID = void*;
using ULONG_PTR = unsigned long*;
using SIZE_T = decltype(sizeof(0));
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably also use these higher up in this file. We can do that as a follow-up.

Co-authored-by: Jeroen Ketema <93738568+jketema@users.noreply.github.com>
MathiasVP and others added 2 commits May 27, 2025 11:45
Co-authored-by: Jeroen Ketema <93738568+jketema@users.noreply.github.com>
Co-authored-by: Jeroen Ketema <93738568+jketema@users.noreply.github.com>
Comment on lines +158 to +160
char* p = reinterpret_cast<char*>(overlapped.hEvent);
sink(p);
sink(*p); // $ MISSING: ir
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this still relevant with the hEvent model removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess there's still flow at runtime, right? buffer and overlapped.hEvent alias, so the call to ReadFileEx will also write user-controlled data to overlapped.hEvent. So if we had proper alias support in dataflow (which we don't) we should get this flow.

@MathiasVP
Copy link
Contributor Author

DCA was uneventful. Merging!

@MathiasVP MathiasVP merged commit 8595bd8 into github:main May 27, 2025
14 checks passed
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