Skip to content

Commit

Permalink
Add a unit test to detect the false negative in rule G306 for os.Mode…
Browse files Browse the repository at this point in the history
…Perm permissions

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
  • Loading branch information
ccojocar committed May 14, 2024
1 parent 417a44c commit dc5e5a9
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion testutils/g306_samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func check(e error) {
}
func main() {
d1 := []byte("hello\ngo\n")
err := ioutil.WriteFile("/tmp/dat1", d1, 0744)
check(err)
Expand Down Expand Up @@ -52,5 +51,25 @@ func main() {
w.Flush()
}
`}, 1, gosec.NewConfig()},
{[]string{`
package main
import (
"io/ioutil"
"os"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func main() {
content := []byte("hello\ngo\n")
err := ioutil.WriteFile("/tmp/dat1", content, os.ModePerm)
check(err)
}
`}, 1, gosec.NewConfig()},
}

0 comments on commit dc5e5a9

Please sign in to comment.