diff --git a/rules/S7427/metadata.json b/rules/S7427/metadata.json new file mode 100644 index 0000000000..2c63c08510 --- /dev/null +++ b/rules/S7427/metadata.json @@ -0,0 +1,2 @@ +{ +} diff --git a/rules/S7427/rust/metadata.json b/rules/S7427/rust/metadata.json new file mode 100644 index 0000000000..a2872e1d5a --- /dev/null +++ b/rules/S7427/rust/metadata.json @@ -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" + } +} diff --git a/rules/S7427/rust/rule.adoc b/rules/S7427/rust/rule.adoc new file mode 100644 index 0000000000..6a7d753fd6 --- /dev/null +++ b/rules/S7427/rust/rule.adoc @@ -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