Skip to content

QL: add unused-field query #7763

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
merged 6 commits into from
May 18, 2022
Merged

QL: add unused-field query #7763

merged 6 commits into from
May 18, 2022

Conversation

erik-krogh
Copy link
Contributor

@erik-krogh erik-krogh commented Jan 26, 2022

Inspired by a recent code-review.

Detects when a field is not bound by the charpred.
Also handles the cases where the field is defined in an abstract super-class.

I fixed all five errors detected by the query. They were pretty benign except for the Python warning in Flask.qll.
(I think the error in Flask.qll was from not copy-pasting a line from the above class, so I did that).

@erik-krogh erik-krogh force-pushed the unused-field branch 3 times, most recently from e2fe297 to 7956b67 Compare March 9, 2022 11:49
@erik-krogh erik-krogh marked this pull request as ready for review March 9, 2022 11:58
@erik-krogh erik-krogh requested review from a team as code owners March 9, 2022 11:58
@tausbn tausbn added the no-change-note-required This PR does not need a change note label Mar 9, 2022
RasmusWL
RasmusWL previously approved these changes Mar 17, 2022
Copy link
Member

@RasmusWL RasmusWL left a comment

Choose a reason for hiding this comment

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

👍 for Python

☺️ that is was only for an experimental query

atorralba
atorralba previously approved these changes Mar 17, 2022
Copy link
Contributor

@atorralba atorralba left a comment

Choose a reason for hiding this comment

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

Good catch! Java 👍

@erik-krogh
Copy link
Contributor Author

relaxed that is was only for an experimental query

The expected output changed after I fixed it, so I pushed the updated output.

Comment on lines 35 to 41
// The `implClz` does not override `field` with a more specific type.
not exists(FieldDecl override |
override = implClz.getDeclaration().getAField() and
override.getName() = field.getName() and
override.hasAnnotation("override") and
override.getVarDecl().getType() != field.getVarDecl().getType()
)
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 relevant? The field should still be mentioned in a char-pred, right? Merely overriding the type doesn't prevent the cartesian product.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, that should not be relevant.
Removing that restriction produces 1 extra alert here:

override VariableDeclarationEntry ast;
.
But that result is an FP for other reasons (the field is bound in DeclarationEntryNode).

I'll look into 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.

I fixed the FP by just looking at the name of the field, instead of checking that the FieldDecl was the same.
(The FieldDecl was different because of an override).

@erik-krogh erik-krogh requested a review from aschackmull April 28, 2022 11:07
// The field is not accessed in the charpred (of any of the classes)
not exists(FieldAccess access |
access.getEnclosingPredicate() =
[clz.getDeclaration().getCharPred(), implClz.getDeclaration().getCharPred()]
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't clz implied by implClz, as you're using the * operator in L16?

Copy link
Contributor

Choose a reason for hiding this comment

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

If not, this can be [clz, implClz].getDeclaration().getCharPred(), right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

isn't clz implied by implClz, as you're using the * operator in L16?

Not necessarily. There are other restrictions in the query that makes it so clz and implClz must sometimes be different classes. (I don't have any examples to link to though).

If not, this can be [clz, implClz].getDeclaration().getCharPred(), right?

Yes it can. I'll do that.

@@ -96,8 +96,6 @@ private class IntentFlagsOrDataChangedSanitizer extends IntentUriPermissionManip
* ```
*/
private class IntentFlagsOrDataCheckedGuard extends IntentUriPermissionManipulationGuard {
Expr condition;
Copy link
Contributor

Choose a reason for hiding this comment

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

ouch! :)

@erik-krogh erik-krogh requested a review from kaeluka April 29, 2022 09:22
Copy link
Contributor

@tausbn tausbn left a comment

Choose a reason for hiding this comment

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

QL-for-QL code looks good to me. 👍

@erik-krogh erik-krogh merged commit 7245591 into github:main May 18, 2022
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.

6 participants