Add a unit test to detect the false negative in rule G306 for os.ModePerm permissions

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
This commit is contained in:
Cosmin Cojocar 2024-05-13 18:19:43 +02:00
parent 417a44c73b
commit dc5e5a99d0

View file

@ -21,7 +21,6 @@ func check(e error) {
}
func main() {
d1 := []byte("hello\ngo\n")
err := ioutil.WriteFile("/tmp/dat1", d1, 0744)
check(err)
@ -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()},
}