From dc5e5a99d0e3df4f6c0720ab29083957b83199b6 Mon Sep 17 00:00:00 2001 From: Cosmin Cojocar Date: Mon, 13 May 2024 18:19:43 +0200 Subject: [PATCH] Add a unit test to detect the false negative in rule G306 for os.ModePerm permissions Signed-off-by: Cosmin Cojocar --- testutils/g306_samples.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/testutils/g306_samples.go b/testutils/g306_samples.go index f8ab32a..0f1e8c9 100644 --- a/testutils/g306_samples.go +++ b/testutils/g306_samples.go @@ -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()}, }