Skip to content

QL: detect unqueryable code #8454

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

erik-krogh
Copy link
Contributor

@erik-krogh erik-krogh commented Mar 15, 2022

Similar to ql/dead-code, but does not consider public APIs as live.

That means any code that doesn't affect any (known) query is flagged.
The query is therefore good at detecting untested code or code that could be deprecated (:eyes: Python).

Shared files where not all languages use all the features have a tendency to be flagged, so a bunch of those have been manually excluded.

There is a whole bunch of existing alerts where unused code exists for completeness, or where the code is only used by queries outside of the github/codeql repo.
So even though there are plenty of results, most of the results should not be fixed.

I still think it's a nice query to have, as it has found some obvious bugs in e.g. JS and GO (see the PRs below).


PRs from this query:
Python: #10317
JS: #8422
Go: #10475
Ruby: #10476
Java: #10486
C: #10573
C#: #10584

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 don't think we should deprecate code just because it doesn't have a use in our own set of queries. For instance, localExprFlow isn't something we're likely to use ourselves, but I've frequently seen QL code "in the wild" that uses it.

Copy link
Contributor

@jbj jbj left a comment

Choose a reason for hiding this comment

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

I don't think we want the DataFlowUtil changes for C++.

@erik-krogh
Copy link
Contributor Author

erik-krogh commented Mar 16, 2022

I reverted the DataFlowUtil.qll deprecations, and deleted some stuff in various /internal/ folder (where it doesn't seem to be exposed elsewhere).

And there's a reason I've set the @problem.severity recommendation, because there's plenty of code that is intentionally unqueryable. But I think it's good to be aware of it.

result.(Module).getAMember().(ClasslessPredicate).getName() = "forceStage" or
result.(ClasslessPredicate).getName() = "forceStage" or
result.(Module).getAMember().(ClasslessPredicate).getName() =
["forceStage", "forceCachingInSameStageforceCachingInSameStage"] or
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like I'm seeing double. Should this be simply forceCachingInSameStage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And the case was also redundant.
The below case in the disjunction already covered it.

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.

4 participants