File tree Expand file tree Collapse file tree 1 file changed +42
-1
lines changed
go/ql/test/library-tests/semmle/go/dataflow/flowsources/local/file Expand file tree Collapse file tree 1 file changed +42
-1
lines changed Original file line number Diff line number Diff line change 11package test
22
3- import "os"
3+ import (
4+ "io/fs"
5+ "io/ioutil"
6+ "os"
7+ )
48
59func open () {
610 file , err := os .Open ("file.txt" ) // $ source
@@ -27,3 +31,40 @@ func readFile() {
2731 }
2832 _ = data
2933}
34+
35+ func readFileIoUtil () {
36+ data , err := ioutil .ReadFile ("file.txt" ) // $source
37+ if err != nil {
38+ return
39+ }
40+ _ = data
41+ }
42+
43+ func getFileFS () fs.ReadFileFS {
44+ return nil
45+ }
46+
47+ func readFileFs () {
48+ data , err := fs .ReadFile (os .DirFS ("." ), "file.txt" ) // $source
49+ if err != nil {
50+ return
51+ }
52+ _ = data
53+
54+ dir := getFileFS ()
55+ data , err = dir .ReadFile ("file.txt" ) // $source
56+
57+ if err != nil {
58+ return
59+ }
60+ _ = data
61+ }
62+
63+ func fsOpen () {
64+ file , err := os .DirFS ("." ).Open ("file.txt" ) // $source
65+ if err != nil {
66+ return
67+ }
68+ defer file .Close ()
69+ file .Read ([]byte {1 , 2 , 3 })
70+ }
You can’t perform that action at this time.
0 commit comments