Shared/C++: Handle non-standard return values in MaD flow sources/sinks#19569
Merged
MathiasVP merged 4 commits intogithub:mainfrom May 23, 2025
Merged
Shared/C++: Handle non-standard return values in MaD flow sources/sinks#19569MathiasVP merged 4 commits intogithub:mainfrom
MathiasVP merged 4 commits intogithub:mainfrom
Conversation
…Output' and 'interpretInput' to handle non-standard return value input/output. This is needed to support C++'s ReturnValue[**] notation.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR extends the MaD flow specification to correctly handle non-standard return-value indirections (e.g. ReturnValue[*]) by delegating to a new getReturnValueKind helper in both the QL and C++ FlowSummary implementations.
Key changes:
- Introduce
getReturnValueKind(string)and updateinterpretOutput/interpretInputto use it whenReturnValuehas an argument. - Delegate
getStandardReturnValueKind()togetReturnValueKind("")in both QL and C++ modules. - Update model-as-data tests to expect indirect return-value flows (fix missing
$ irmarks).
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| shared/dataflow/codeql/dataflow/internal/FlowSummaryImpl.qll | Add getReturnValueKind, extend interpretOutput/interpretInput to handle starred return kinds. |
| cpp/ql/test/library-tests/dataflow/models-as-data/tests.cpp | Update test expectations for indirect return-value sources. |
| cpp/ql/lib/semmle/code/cpp/dataflow/internal/FlowSummaryImpl.qll | Route getStandardReturnValueKind() through new getReturnValueKind. |
jketema
reviewed
May 23, 2025
Contributor
Author
Thanks! Yeah, I've started a DCA run now. I don't think we have any MaD specifications that are currently affected by this, but it doesn't hurt to double check |
Contributor
Author
|
DCA was uneventful (as expected) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In #19563 @jketema is adding flow sources for (among other things) GetCommandLineA which should have the following MaD specification:
["", "", False, "GetCommandLineA", "", "", "ReturnValue[*]", "local", "manual"](because it's not the pointer returned by
GetCommandLineAthat's user controlled - it's the data that's pointed to!)However, we noticed that this is not parsed correctly by the current implementation of
SourceSinkInterpretation::interpretOutputsince it only has a case forgetStandardReturnValueKind(andReturnValueis the standard return value kind, notReturnValue[*]).This PR fixes that missing case, and I've checked that this makes the MaD specifications we want to have in #19563 work 🎉