Skip to content

Commit

Permalink
Add intro texts to code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
teemu-rytilahti-sonarsource committed Jan 30, 2025
1 parent 752c391 commit 6a67026
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions rules/S5443/go/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ include::../recommended.adoc[]

== Sensitive Code Example

Examples of sensitive file creation:

[source,go]
----
file, _ = os.Create("/tmp/tempfile.txt") // Sensitive
Expand All @@ -17,6 +19,8 @@ file, _ := os.OpenFile("/tmp/tempfile.txt", os.O_CREATE, 0755) // Sensitive
os.WriteFile("/tmp/tempfile.txt", []byte{"sensitive"}, 0755) // Sensitive
----

Example of sensitive directory creation:

[source,go]
----
tempdir := "/tmp/tempdir/"
Expand All @@ -26,11 +30,15 @@ file, _ := os.Create("/tmp/tempdir/tempfile.txt")

== Compliant Solution

Compliant temporary file creation:

[source,go]
----
file, _ := os.CreateTemp("", "example-pattern") // Compliant
----

Compliant temporary directory creation:

[source,go]
----
dir, _ := os.MkdirTemp("", "example-directory") // Compliant
Expand Down

0 comments on commit 6a67026

Please sign in to comment.