Skip to content

C++: Flow out of writes to iterators#12050

Merged
MathiasVP merged 6 commits into
github:mathiasvp/replace-ast-with-ir-use-usedataflowfrom
MathiasVP:flow-out-of-iterators-3
Feb 3, 2023
Merged

C++: Flow out of writes to iterators#12050
MathiasVP merged 6 commits into
github:mathiasvp/replace-ast-with-ir-use-usedataflowfrom
MathiasVP:flow-out-of-iterators-3

Conversation

@MathiasVP
Copy link
Copy Markdown
Contributor

Ideally, this PR would just be adding the one disjunct to isIteratorUse that I've added in 88338bd, but the isIteratorUse code was assuming that we had the Operand that represented the actual dereference when using the iterator (i.e., the operand representing *it for some iterator it). This is obviously not true if the iterator is passed to a function (which then writes to the iterator), so I had to shuffle things around in isChiBeforeIteratorUse and extend indirectConversionFlowStep to treat dereferences as conversions (when the indirection index is changed accordingly).

The change to indirectConversionFlowStep looks like this is giving us a bunch of new good results on Samate 🎉 (and AFAICT, it's also responsible for the small changes to path explanations).

@MathiasVP MathiasVP requested a review from a team as a code owner January 31, 2023 17:11
@github-actions github-actions Bot added the C++ label Jan 31, 2023
@MathiasVP MathiasVP added the no-change-note-required This PR does not need a change note label Jan 31, 2023
@MathiasVP MathiasVP force-pushed the flow-out-of-iterators-3 branch from 5314c88 to eb31160 Compare February 1, 2023 13:42
Copy link
Copy Markdown
Contributor

@jketema jketema left a comment

Choose a reason for hiding this comment

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

Initial comments.

I'm still trying to wrap my head around isChiAfterIteratorArgument.

Comment thread cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternalsCommon.qll Outdated
it += source();
sink(*it); // $ ast,ir
sink(vs[1]);
sink(vs[1]); // $ SPURIOUS: ir
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Where is this coming from?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This one is super annoying. What happens is:

  1. There's a write to the iterator at it += source();
  2. This write propagates to it on the next line at sink(*it);
  3. There's a taint step from it to *it
  4. The *it is seen as a use of vs (because of the line it = vs.begin();)
  5. There's use-use flow from *it (which is a use of vs) to vs on the line at sink(vs[1]);
  6. There's a taint step from vs to vs[1]

Individually all of these steps make sense, but the final result is that we have taint flow from the write to the iterator to the use of the underlying container 😭. This only happens in taint configurations, though (since it requires a taint step to go from it to *it).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation. I think this would warrant a comment in the test that briefly describes why this is happening.

Comment thread cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternalsCommon.qll Outdated
@MathiasVP MathiasVP merged commit 77250af into github:mathiasvp/replace-ast-with-ir-use-usedataflow Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C++ 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.

2 participants