Skip to content

Conversation

geoffw0
Copy link
Contributor

@geoffw0 geoffw0 commented Jun 17, 2020

General models for class copy constructors, move constructors, copy assignment and move assignment. Removed the model of the std::string constructor as it's now redundant.

@geoffw0 geoffw0 added the C++ label Jun 17, 2020
@geoffw0 geoffw0 requested a review from a team as a code owner June 17, 2020 14:56
Copy link
Contributor

@MathiasVP MathiasVP left a comment

Choose a reason for hiding this comment

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

I like it! Haven't looked through it all yet, so I only have one comment so far.

@jbj jbj self-requested a review June 17, 2020 15:37
input.isParameter(idx) and
output.isReturnValue() and
not this.(CopyConstructor).hasDataFlow(input, output) and // don't duplicate where we have data flow
not this.(MoveConstructor).hasDataFlow(input, output) // don't duplicate where we have data flow
Copy link
Contributor

Choose a reason for hiding this comment

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

I find it controversial to model that there is taint from any constructor argument to the constructed object. It's almost like modelling that there is taint from function arguments to function return value for any function.

Copy link
Contributor

Choose a reason for hiding this comment

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

To elaborate, we've decided in the team that there should be object-to-field taint flow. This model would introduce field-to-object taint flow, which by transitivity gets us field-to-unrelated-field taint flow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I see your point that it's similar to any function call taking inputs and producing an object. I've deleted the case for the general constructor but added one for 'conversion constructors' (that are important and much more likely to behave as we expect).

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems less dangerous, and I can see that users might reasonably expect C x = a; to propagate taint even if a is not of type C. It's less clear to me whether they'll expect C x(a); to propagate taint from a to x in all cases.

We're not currently using ConversionConstructor in production, and I think it needs a bit of dusting off. Its charpred excludes copy constructors but not move constructors. That's been worked around by excluding move constructors in its getCanonicalQLClass override, but surely that exclusion should be moved to its charpred?

I still find this rule controversial, and I find it likely we'll have to drop it when adding object-to-field flow (https://github.com/github/codeql-c-analysis-team/issues/103). In any case, please run CPP-Differences.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its charpred excludes copy constructors but not move constructors.

Yes, I noticed that, I'll fix it in a separate PR.

In any case, please run CPP-Differences.

Diff is running here: https://jenkins.internal.semmle.com/job/Changes/job/CPP-Differences/1213/

Copy link
Contributor Author

@geoffw0 geoffw0 Jun 24, 2020

Choose a reason for hiding this comment

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

... and possibly openjdk as well.

New diff job excluding wireshark and openjdk: https://jenkins.internal.semmle.com/job/Changes/job/CPP-Differences/1226/
New diff job of just wireshark: TODO
New diff job of just openjdk: TODO

Copy link
Contributor

Choose a reason for hiding this comment

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

Be sure that your branch includes #3754. Otherwise openjdk will continue to fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Success! - https://jenkins.internal.semmle.com/job/Changes/job/CPP-Differences/1239/

And there are no changes, so that's good.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised there are no changes. But at least that makes me more confident about merging this PR even though it might have less of an impact than I hoped.

@jbj jbj merged commit 50cd759 into github:master Jul 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants