Skip to content

Commit dc5e5a9

Browse files
committedMay 14, 2024
Add a unit test to detect the false negative in rule G306 for os.ModePerm permissions
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
1 parent 417a44c commit dc5e5a9

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed
 

‎testutils/g306_samples.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ func check(e error) {
2121
}
2222
2323
func main() {
24-
2524
d1 := []byte("hello\ngo\n")
2625
err := ioutil.WriteFile("/tmp/dat1", d1, 0744)
2726
check(err)
@@ -52,5 +51,25 @@ func main() {
5251
w.Flush()
5352
5453
}
54+
`}, 1, gosec.NewConfig()},
55+
{[]string{`
56+
package main
57+
58+
import (
59+
"io/ioutil"
60+
"os"
61+
)
62+
63+
func check(e error) {
64+
if e != nil {
65+
panic(e)
66+
}
67+
}
68+
69+
func main() {
70+
content := []byte("hello\ngo\n")
71+
err := ioutil.WriteFile("/tmp/dat1", content, os.ModePerm)
72+
check(err)
73+
}
5574
`}, 1, gosec.NewConfig()},
5675
}

0 commit comments

Comments
 (0)