-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Data flow: Move C# lambda flow logic into shared library #5311
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
Conversation
In Java, lambdas are just a special case of construction of anonymous classes. This means that the implicit assumption that a lambda object only has one method that can be called breaks for Java, so the interface needs to account for that somehow. |
The 4% increases in analysis time for two projects in https://jenkins.internal.semmle.com/job/Changes/job/CPP-Differences/1786/ appear to be just noise: they're attributed to queries without data flow. |
I did consider having an extra "call kind" column in both |
I'm not entirely sure. I missed this in our last round of coordination, so I haven't thought a lot about what it would look like. |
0f5b89b
to
b11e151
Compare
I have rebased this PR, added a "call kind" column, and restarted difference jobs. |
exists(Ssa::Definition def | | ||
LocalFlow::localSsaFlowStep(def, nodeFrom, nodeTo) and | ||
LocalFlow::usesInstanceField(def) and | ||
preservesValue = true | ||
) | ||
or | ||
exists(LambdaConfiguration x, DelegateCreation dc | | ||
x.hasExprPath(dc.getArgument(), nodeFrom.(ExprNode).getControlFlowNode(), dc, | ||
nodeTo.(ExprNode).getControlFlowNode()) and | ||
preservesValue = false | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are these two steps? I can guess what the event-step below is for, but these two are somewhat opaque to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first step is for including SSA with fields, because field flow is not yet modelled in the data flow loop. The second consists of two steps that are specific to delegates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shared bits LGTM. I have not reviewed the C# changes.
@tamasvajk : Could you take a look at the C# bits? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mostly checked the test result changes, they seem correct. The diff job shows a couple of new issues (cs/cleartext-storage-of-sensitive-information
, cs/user-controlled-bypass
) that doesn't seem to be caused by simple wobbliness. Are those true positives?
This is caused by 25adcfc, which adds missing flow from parameters into SSA phi nodes. |
This PR adds support for resolving lambda calls to the shared data-flow library. The interface to be implemented by each language is
with the semantics that
call
will resolve toc
if there is a data-flow path fromcreation
toreceiver
.The implementation is, for now, quite simple (ported from the existing C# implementation): read/store steps and flow-through is not taken into account. However, higher-order flow is supported, which makes the data-flow analysis non-linearly recursive. Adding support for contents and flow-through is postponed as future work.
The implementation keeps track of a one-level call context, which means that we are able to handle situations like this:
However, since we only track one level the following example will have false-positive flow:
Commit-by-commit review is strongly encouraged.
https://jenkins.internal.semmle.com/job/Changes/job/CSharp-Differences/914/https://jenkins.internal.semmle.com/job/Changes/job/CPP-Differences/1786/
https://jenkins.internal.semmle.com/job/Changes/job/Java-Differences/1201/
https://jenkins.internal.semmle.com/job/Changes/job/Python-Differences/445/
https://jenkins.internal.semmle.com/job/Changes/job/CSharp-Differences/946/
https://jenkins.internal.semmle.com/job/Changes/job/CPP-Differences/1839/
https://jenkins.internal.semmle.com/job/Changes/job/Java-Differences/1227/
https://jenkins.internal.semmle.com/job/Changes/job/Python-Differences/464/