Skip to content
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

C++: Remove pointer/pointee conflation from models of "pure" functions #18556

Merged

Conversation

MathiasVP
Copy link
Contributor

@MathiasVP MathiasVP commented Jan 21, 2025

This PR cleans up the taint-flow model for the PureStrFunction class. Previously, this was conflating pointers and their indirections which caused false flow in some cases. See the first commit for an example of this.

Additionally, I added a dataflow model for the cases where the pointer is actually preserved.

DCA shows 3 lost results, and they appear to be FPs that are now correctly removed.

@Copilot Copilot bot review requested due to automatic review settings January 21, 2025 20:46
@MathiasVP MathiasVP requested a review from a team as a code owner January 21, 2025 20:46

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again, by re-requesting a review.

@MathiasVP MathiasVP added the no-change-note-required This PR does not need a change note label Jan 21, 2025
@github-actions github-actions bot added C++ and removed no-change-note-required This PR does not need a change note labels Jan 21, 2025
@MathiasVP MathiasVP added the no-change-note-required This PR does not need a change note label Jan 21, 2025
@paldepind paldepind self-assigned this Jan 23, 2025
@@ -26,22 +27,43 @@ private class PureStrFunction extends AliasFunction, ArrayFunction, TaintFunctio
}

Copy link
Contributor

Choose a reason for hiding this comment

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

We could add a helper predicate for the locale argument check?

Suggested change
/** Holds if `i` is a locale parameter that does not carry taint. */
private predicate isLocaleParameter(ParameterIndex i) {
this.getName().matches("%\\_l") and i + 1 = this.getNumberOfParameters()
}

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! Fixed in 7792839

cpp/ql/lib/semmle/code/cpp/models/implementations/Pure.qll Outdated Show resolved Hide resolved
// indirection of the parameter. Otherwise, there is taint from the
// parameter.
// 2. If the return value is of a pointer type then there is taint to the
// indirection of the return. Otherwise, there is taint to the return.
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to move this comment up before the exists given that it concerns both the stuff inside the exists and also the conjunct after it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Fixed in 67e3b69

@MathiasVP
Copy link
Contributor Author

Thanks for the review, @paldepind! I believe I've resolved all your comments now.

Copy link
Contributor

@paldepind paldepind left a comment

Choose a reason for hiding this comment

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

Looks great to me 👍

@MathiasVP MathiasVP merged commit ccb28ed into github:main Jan 23, 2025
13 checks passed
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