Create rule S7427: Null pointers should not be transmuted (#4768)
* Create rule S7427 * 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:
parent
31e8111116
commit
e1ee16f500
2
rules/S7427/metadata.json
Normal file
2
rules/S7427/metadata.json
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
{
|
||||||
|
}
|
24
rules/S7427/rust/metadata.json
Normal file
24
rules/S7427/rust/metadata.json
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"title": "Null pointers should not be transmuted",
|
||||||
|
"type": "BUG",
|
||||||
|
"status": "ready",
|
||||||
|
"remediation": {
|
||||||
|
"func": "Constant\/Issue",
|
||||||
|
"constantCost": "5min"
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"clippy"
|
||||||
|
],
|
||||||
|
"defaultSeverity": "Major",
|
||||||
|
"ruleSpecification": "RSPEC-7427",
|
||||||
|
"sqKey": "S7427",
|
||||||
|
"scope": "All",
|
||||||
|
"defaultQualityProfiles": ["Sonar way"],
|
||||||
|
"quickfix": "unknown",
|
||||||
|
"code": {
|
||||||
|
"impacts": {
|
||||||
|
"RELIABILITY": "HIGH"
|
||||||
|
},
|
||||||
|
"attribute": "LOGICAL"
|
||||||
|
}
|
||||||
|
}
|
24
rules/S7427/rust/rule.adoc
Normal file
24
rules/S7427/rust/rule.adoc
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
== Why is this an issue?
|
||||||
|
|
||||||
|
Transmuting a null pointer is undefined behavior and can lead to unpredictable program crashes and security vulnerabilities.
|
||||||
|
|
||||||
|
=== Code examples
|
||||||
|
|
||||||
|
==== Noncompliant code example
|
||||||
|
|
||||||
|
[source,rust,diff-id=1,diff-type=noncompliant]
|
||||||
|
----
|
||||||
|
let null_ref: &u64 = unsafe { std::mem::transmute(0 as *const u64) }; // Noncompliant: Transmuting a null pointer.
|
||||||
|
----
|
||||||
|
|
||||||
|
==== Compliant solution
|
||||||
|
|
||||||
|
[source,rust,diff-id=1,diff-type=compliant]
|
||||||
|
----
|
||||||
|
let null_ref: Option<&u64> = None; // Compliant: Use Option to represent nullable references.
|
||||||
|
----
|
||||||
|
|
||||||
|
== Resources
|
||||||
|
=== Documentation
|
||||||
|
|
||||||
|
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#transmuting_null
|
Loading…
x
Reference in New Issue
Block a user