Skip to content

Conversation

hvitved
Copy link
Contributor

@hvitved hvitved commented Nov 7, 2023

This PR switches out the existing type tracking library, codeql.ruby.typetracking.TypeTracker.qll, with a new library based on the shared type tracking library, exposed as codeql.ruby.typetracking.TypeTracking.qll. The old type tracking library has been deprecated.

The consistency checks of the shared type tracking library revealed a lot of issues, which have been fixed on #14787, but also some here:

  • Consider any (non-parameter) implicit SSA write definition a local source node, for example local exception variables introduced in rescue clauses.
  • Consider any target of a store (including with(out)-content checks) to be a local source node. (This is what results in the improved expected test output.)

@github-actions github-actions bot added the Ruby label Nov 7, 2023
@hvitved hvitved force-pushed the ruby/shared-type-tracking branch 3 times, most recently from 8ccdce3 to 40e6a32 Compare November 7, 2023 14:45
@hvitved hvitved force-pushed the ruby/shared-type-tracking branch 13 times, most recently from 9142613 to 582296d Compare November 20, 2023 10:36
@hvitved hvitved force-pushed the ruby/shared-type-tracking branch from 582296d to 6ce8e05 Compare November 20, 2023 15:03
@hvitved hvitved marked this pull request as ready for review November 21, 2023 10:56
@hvitved hvitved requested a review from a team as a code owner November 21, 2023 10:56
@sidshank sidshank requested a review from aibaars December 4, 2023 12:09
Copy link
Contributor

@aibaars aibaars 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.

*/
pragma[inline]
LocalSourceNode backtrack(TypeBackTracker t2, TypeBackTracker t) { t2 = t.step(result, this) }
LocalSourceNode backtrack(TypeBackTracker t2, TypeBackTracker t) { t = t2.step(result, this) }
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 change correct? Were the parameters of backtrack swapped? We might want to check that all the places where we use backtrack are still correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is because the shared library (which defines step) has the arguments reversed. I decided to keep the order as-is in backtrack.

private import codeql.ruby.DataFlow
private import codeql.ruby.controlflow.CfgNodes
private import codeql.ruby.typetracking.TypeTracker
private import codeql.ruby.typetracking.internal.TypeTrackingImpl
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this really need to import the Impl library? I think ideally the Impl module is only used when instantiating the library. The modules that are built on top should ideally only use the "public facing" bits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does, because the code refers to StepSummary, which is considered internal in the new library.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I guess we cannot avoid that, can we? Or should StepSummary perhaps be part of the public interface?

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 prefer to keep it internal, at least for now. It is not something I expect we need to use very often.

* A description of a step on an inter-procedural data flow path.
*/
cached
newtype TStepSummary =
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that most/all things in this module are deprecated. Shall we add a deprecation note to the file-level QL doc explaining what to use instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea.

| array_flow.rb:940:18:940:78 | # $ hasValueFlow=91.1 $ hasValueFlow=91.2 $ hasValueFlow=91.3 | Missing result:hasValueFlow=91.3 |
| array_flow.rb:957:28:957:46 | # $ hasValueFlow=93 | Missing result:hasValueFlow=93 |
| array_flow.rb:958:28:958:46 | # $ hasValueFlow=93 | Missing result:hasValueFlow=93 |
| array_flow.rb:1018:16:1018:36 | # $ hasValueFlow=99.2 | Missing result:hasValueFlow=99.2 |
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that a lot of missing results are now gone. This is great, however, I'm curious why this is happening. I suppose the shared library is better than the old?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because we now consider any target of a store (including with(out)-content checks) to be a local source node.

@hvitved hvitved merged commit dde83b6 into github:main Dec 5, 2023
@hvitved hvitved deleted the ruby/shared-type-tracking branch December 5, 2023 19:12
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