rspec/rules/S2612/go/rule.adoc

87 lines
1.3 KiB
Plaintext
Raw Normal View History

include::../description.adoc[]
include::../ask-yourself.adoc[]
include::../recommended.adoc[]
== Sensitive Code Example
For https://pkg.go.dev/os#Chmod[Chmod() in the `os` package]:
[source,go,diff-id=1,diff-type=noncompliant]
----
import (
"os"
)
func main() {
err := os.Chmod("/tmp/fs", 0777) // Sensitive
if err != nil {
panic(err)
}
}
----
For https://pkg.go.dev/golang.org/x/sys@v0.11.0/unix#Umask[Umask() in the `syscall` package]:
[source,go,diff-id=2,diff-type=noncompliant]
----
import (
"golang.org/x/sys/unix"
)
func main() {
oldMask := unix.Umask(0) // Sensitive
}
----
== Compliant Solution
For https://pkg.go.dev/os#Chmod[Chmod() in the `os` package]:
[source,go,diff-id=1,diff-type=compliant]
----
import (
"os"
)
func main() {
err := os.Chmod("/tmp/fs", 0770)
if err != nil {
panic(err)
}
}
----
For https://pkg.go.dev/syscall#Umask[`Umask()` in the `syscall` package]:
[source,go,diff-id=2,diff-type=compliant]
----
import (
"golang.org/x/sys/unix"
)
func main() {
oldMask := unix.Umask(0007)
}
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]