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

Lint permissions.set_readonly(false) #9702

Closed
Alexendoo opened this issue Oct 24, 2022 · 6 comments
Closed

Lint permissions.set_readonly(false) #9702

Alexendoo opened this issue Oct 24, 2022 · 6 comments
Assignees
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy

Comments

@Alexendoo
Copy link
Member

Alexendoo commented Oct 24, 2022

What it does

The lint would catch any usage of Permissions::set_readonly called with false

.set_readonly(false) on unix platforms sets the file to be world writable - rust-lang/rust#101644

Lint Name

permissions_set_readonly_false

Category

suspicious

Advantage

The behaviour is surprising, so a lint to inform people that it's probably not doing what they expect would be useful

Drawbacks

If someone knows about that behaviour and is using it intentionally it would be a false positive, however in that case the #[allow] would be a good indicator to others that it is intentional

It's possible that the behaviour will be changed or deprecated upstream before the lint is written

Example

let f = File::create("foo.txt")?;
let metadata = f.metadata()?;
let mut permissions = metadata.permissions();

permissions.set_readonly(false);
@Alexendoo Alexendoo added good-first-issue These issues are a good way to get started with Clippy A-lint Area: New lints labels Oct 24, 2022
@Alexendoo
Copy link
Member Author

Hi, welcome to Clippy!

The most direct way would be to take a look at the expression's kind to see if it's an ExprKind::Lit, there you can check that the literal is a LitKind::Bool(false)

@Alexendoo
Copy link
Member Author

Alexendoo commented Oct 28, 2022

It could be, there is https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/consts/fn.constant_simple.html

It's not a full const evaluator so it wouldn't be catching [Method]Calls, the main thing it'd get here would be consts but that doesn't seem super likely to occur

chansuke pushed a commit to chansuke/rust-clippy that referenced this issue Dec 11, 2022
chansuke pushed a commit to chansuke/rust-clippy that referenced this issue Dec 12, 2022
chansuke pushed a commit to chansuke/rust-clippy that referenced this issue Dec 19, 2022
bors added a commit that referenced this issue Dec 20, 2022
add [`permissions_set_readonly_false`] #9702

Add slight modification on [this PR](#9744).

---

changelog: New lint [`permissions_set_readonly_false`]
[#10063](#10063)
<!-- changelog_checked -->
@Alexendoo
Copy link
Member Author

Added by #10063

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

No branches or pull requests

2 participants
@Alexendoo and others