Create rule S7448: Unix file permissions should be set with octal values (#4792)

* Create rule S7448

* Update RSPEC

---------

Co-authored-by: yassin-kammoun-sonarsource <yassin-kammoun-sonarsource@users.noreply.github.com>
Co-authored-by: yassin-kammoun-sonarsource <yassin.kammoun@sonarsource.com>
This commit is contained in:
github-actions[bot] 2025-03-19 14:06:06 +01:00 committed by GitHub
parent 28e7cab961
commit b294a06b26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,2 @@
{
}

View File

@ -0,0 +1,24 @@
{
"title": "Unix file permissions should be set with octal values",
"type": "BUG",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "5min"
},
"tags": [
"clippy"
],
"defaultSeverity": "Major",
"ruleSpecification": "RSPEC-7448",
"sqKey": "S7448",
"scope": "All",
"defaultQualityProfiles": ["Sonar way"],
"quickfix": "unknown",
"code": {
"impacts": {
"RELIABILITY": "MEDIUM"
},
"attribute": "LOGICAL"
}
}

View File

@ -0,0 +1,33 @@
== Why is this an issue?
Using non-octal values to set Unix file permissions is problematic because they are converted to octal internally, which can lead to unexpected file permissions and potential security issues.
=== Code examples
==== Noncompliant code example
[source,rust,diff-id=1,diff-type=noncompliant]
----
use std::fs::OpenOptions;
use std::os::unix::fs::OpenOptionsExt;
let mut options = OpenOptions::new();
options.mode(644); // Noncompliant: Non-octal value used.
----
==== Compliant solution
[source,rust,diff-id=1,diff-type=compliant]
----
use std::fs::OpenOptions;
use std::os::unix::fs::OpenOptionsExt;
let mut options = OpenOptions::new();
options.mode(0o644); // Compliant: Octal value used.
----
== Resources
=== Documentation
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#non_octal_unix_permissions