Skip to content

Java/C#: exclude FunctionalExprs from DataFlowTargetApi #11623

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

Conversation

jcogs33
Copy link
Contributor

@jcogs33 jcogs33 commented Dec 8, 2022

Description

This PR updates DataFlowTargetApi to exclude functional expressions.

Consideration

  • Please let me know if the exclusion for C# is correct as I don't have much experience with C#.
  • Are there existing library tests for DataFlowTargetApi where I could add a test case for this scenario? I couldn't find any existing tests in the library-tests directory, but I may have missed them.
  • Does a change like this need a DCA run?
  • Is this change minor enough that I can add the no-change-note-required label?

@jcogs33 jcogs33 changed the title Java: exclude FunctionalExprs from DataFlowTargetApi Java/C#: exclude FunctionalExprs from DataFlowTargetApi Dec 8, 2022
@jcogs33 jcogs33 marked this pull request as ready for review December 8, 2022 16:01
@jcogs33 jcogs33 requested review from a team as code owners December 8, 2022 16:01
Copy link
Contributor

@aschackmull aschackmull left a comment

Choose a reason for hiding this comment

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

Java part LGTM. When I did a quick test on a C# db, then the C# change didn't appear to have any effect, so maybe these are already excluded somehow? I.e. the following predicate appears empty:

predicate test(TargetApiSpecific api) {
  isRelevantForModels(api) and
  api instanceof CS::AnonymousFunctionExpr
}

@aschackmull
Copy link
Contributor

  • Does a change like this need a DCA run?

No, that shouldn't be necessary.

  • Is this change minor enough that I can add the no-change-note-required label?

Yes, I think so. It doesn't affect any normal queries.

@michaelnebel
Copy link
Contributor

michaelnebel commented Dec 9, 2022

Java part LGTM. When I did a quick test on a C# db, then the C# change didn't appear to have any effect, so maybe these are already excluded somehow? I.e. the following predicate appears empty:

predicate test(TargetApiSpecific api) {
  isRelevantForModels(api) and
  api instanceof CS::AnonymousFunctionExpr
}

I think that:

api.getDeclaringType().getNamespace().getFullName() != ""

implies (by accident)

not api instanceof CS::AnonymousFunctionExpr

https://github.com/github/codeql/blob/main/csharp/ql/src/utils/modelgenerator/internal/CaptureModelsSpecific.qll#L38

In any case, I think the case for anonymous functions should be explicit in C# as well.

michaelnebel
michaelnebel previously approved these changes Dec 9, 2022
Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

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

Looks good to me, but try and run DCA before mad-queries.qls before merging to see, if we overlooked something.

@michaelnebel
Copy link
Contributor

michaelnebel commented Dec 9, 2022

  • Does a change like this need a DCA run?

I think we should try and run DCA to see the impact on the generated models.
There exist a a query suite in DCA called mad-queries.qls for both Java and C# and it will report the difference in the generated models on the PR against those generated on main on the projects that are being analyzed.
Maybe run the query for java on commons-io and for C# on the dotnet project.

@jcogs33 jcogs33 added the no-change-note-required This PR does not need a change note label Dec 9, 2022
@jcogs33
Copy link
Contributor Author

jcogs33 commented Dec 9, 2022

Maybe run the query for java on commons-io and for C# on the dotnet project.

@michaelnebel I haven't run DCA on specific projects before, so can I confirm that I would need to use the "Manually select sources" option for this? (That's what I did for the two "CustomSources" DCA runs above, just want to make sure that was correct 🙂)

@michaelnebel
Copy link
Contributor

Yes, you are right - you need to select custom sources and for C#, it is enough to select the dotnet/dotnet project.
Also, to get the numbers reported by DCA you also need to add the mad-queries.qls as *uninterpretedq-queries. This is done via adding an option.
There is a short description on https://github.com/github/codeql-csharp-team/issues/223 in the documentation section on how to achieve this.
You will need wait executing the DCA run until https://github.com/github/codeql-dca/pull/1310 is merged as I have just renamed negative summary models to neutral models and merged that into main (and now we need to the corresponding rename in DCA before we can get the summaries reported here).

@jcogs33
Copy link
Contributor Author

jcogs33 commented Dec 12, 2022

Thanks! I see you've rerun DCA for this.

@michaelnebel
Copy link
Contributor

(1) DCA reports no changes in the generated models for C# (as we expected).
(2) DCA for Java failed for some reason. Will trigger DCA run again.

@michaelnebel
Copy link
Contributor

@jcogs33 : There are no changes in the number of generated models for commons-io (there appears to be some flakyness with the neutral numbering reported by DCA). Is there a project in DCA, where we expected a difference in the produced models?

@michaelnebel
Copy link
Contributor

@jcogs33 : There are no changes in the number of generated models for commons-io (there appears to be some flakyness with the neutral numbering reported by DCA). Is there a project in DCA, where we expected a difference in the produced models?

The flakyness is probably because the branch needs to be rebased on main (the PR renaming the negative to neutral models has been merged in the meantime).
Could you rebase the branch and re-execute DCA?

@jcogs33 jcogs33 force-pushed the jcogs33/exclude-funcexpr-from-dataflowtargetapi branch from 66af985 to 91c1ec3 Compare December 13, 2022 14:54
@jcogs33
Copy link
Contributor Author

jcogs33 commented Dec 14, 2022

@michaelnebel The new DCA run looks good to me. Let me know if you disagree.

@michaelnebel
Copy link
Contributor

michaelnebel commented Dec 14, 2022

@michaelnebel The new DCA run looks good to me. Let me know if you disagree.

The numbers reported by DCA looks a bit wrong. The summary section shows that all the neutral models are unique in both variants of the analysis.
image

This is not a problem with the content of this PR, but rather a problem with the DCA implementation.
I will try and fix the DCA implementation and then we can re-execute DCA again.

@michaelnebel
Copy link
Contributor

michaelnebel commented Dec 14, 2022

DCA looks good now :-)
PR is good to be merged.

@jcogs33
Copy link
Contributor Author

jcogs33 commented Dec 14, 2022

PR is good to be merged.

@michaelnebel Can you re-approve? Rebasing yesterday dismissed your approval.

@jcogs33
Copy link
Contributor Author

jcogs33 commented Dec 14, 2022

Thanks @tamasvajk! 😄

@jcogs33 jcogs33 merged commit 33955ee into github:main Dec 14, 2022
@jcogs33 jcogs33 deleted the jcogs33/exclude-funcexpr-from-dataflowtargetapi branch December 14, 2022 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# Java no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants