C++: Refine Node.asDefinition#19001
Merged
MathiasVP merged 8 commits intogithub:mainfrom Mar 13, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request.
Files not reviewed (6)
- cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll: Language not supported
- cpp/ql/src/Security/CWE/CWE-079/CgiXss.ql: Language not supported
- cpp/ql/src/Security/CWE/CWE-114/UncontrolledProcessOperation.ql: Language not supported
- cpp/ql/src/Security/CWE/CWE-134/UncontrolledFormatString.ql: Language not supported
- cpp/ql/src/Security/CWE/CWE-170/ImproperNullTerminationTainted.ql: Language not supported
- cpp/ql/src/Security/CWE/CWE-190/ArithmeticTainted.ql: Language not supported
Tip: If you use Visual Studio Code, you can request a review from Copilot before you push from the "Source Control" tab. Learn more
jketema
reviewed
Mar 13, 2025
Contributor
jketema
left a comment
There was a problem hiding this comment.
Bit of nitpicking below, otherwise LGTM.
cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll
Outdated
Show resolved
Hide resolved
cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll
Outdated
Show resolved
Hide resolved
cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll
Outdated
Show resolved
Hide resolved
cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll
Outdated
Show resolved
Hide resolved
cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll
Outdated
Show resolved
Hide resolved
Co-authored-by: Jeroen Ketema <93738568+jketema@users.noreply.github.com>
Co-authored-by: Jeroen Ketema <93738568+jketema@users.noreply.github.com>
Co-authored-by: Jeroen Ketema <93738568+jketema@users.noreply.github.com>
Co-authored-by: Jeroen Ketema <93738568+jketema@users.noreply.github.com>
Co-authored-by: Jeroen Ketema <93738568+jketema@users.noreply.github.com>
jketema
approved these changes
Mar 13, 2025
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 #18942 we're slightly changing how we handle uncertain writes. For example, consider this example:
On
mainwe get dataflow from// 1to// 3by realizing that// 2is an uncertain write (i.e., it doesn't overwrite the entire buffer), and so we insert a direct def-use step from// 1to// 3here.This has always been a bit of a hack since this can create a quadratic number of def-use edges. Luckily, the
DataFlowIntegrationmodule that Schack is porting to C++ in #18942 does flow through uncertain writes slightly differently. In the above example, it adds a step from// 1to// 2and (because//2is an uncertain definition) another step from// 2to// 3. This gets rid of the quadratic number of steps 🎉However, we have some queries that assume that, if we reach a
StoreInstructionthen we'll continue with that def-use flow. For example here we place a barrier when writing to a non-char pointer type since we don't want to track flow to arithmetic values in that query.Now that we have other flows out of that
StoreInstructionthis no longer holds true. So this PR adds a column toasDefinitionso that it's possible to check whether or not the definition overwrites the entire buffer. I also added convenience predicatesasCertainDefinitionandasUncertainDefinitionto avoid memorizing what that boolean means, and changed all our queries to use the new API.New results
We have three new results:
openjdk-jdkresult is a new TP. Previously, we were marking this assignment as a barrier, and we obviusly don't want to do that as this is basically astrcpy-like function. By only marking certain writes as barriers this is no longer considered a barrier for the query.vim__vimresult also looks TP-ish. Onmainwe place a barrier on this assignment, and now we don't do that since the write only partially overwrites the buffer. As far as I can tell this write sits inside a very large loop that iterators over some tainted data, and so we write each character individually intoformat(i.e., we grab each character here). So I thinks this result is genuine as well.neovim__neovimresult is identical to thevim__vimresult