Fix gosec vulnerabilities: file and directory permissions (#142)
- Fix G301: Poor file permissions used when creating a directory. - Fix G306: Poor file permissions used when writing to a new file. See https://github.com/securego/gosec#available-rules
This commit is contained in:
parent
0d9680fd45
commit
b052143b5a
4
main.go
4
main.go
@ -90,10 +90,10 @@ func run(flags userFlags) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create the file
|
// create the file
|
||||||
err = os.MkdirAll(filepath.Dir(flags.outFile), 0755)
|
err = os.MkdirAll(filepath.Dir(flags.outFile), 0750)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return ioutil.WriteFile(flags.outFile, buf.Bytes(), 0644)
|
return ioutil.WriteFile(flags.outFile, buf.Bytes(), 0600)
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
// copy copies srcPath to destPath, dirs and files
|
// copy copies srcPath to destPath, dirs and files
|
||||||
func copy(srcPath, destPath string, item os.FileInfo) error {
|
func copy(srcPath, destPath string, item os.FileInfo) error {
|
||||||
if item.IsDir() {
|
if item.IsDir() {
|
||||||
if err := os.MkdirAll(destPath, os.FileMode(0755)); err != nil {
|
if err := os.MkdirAll(destPath, os.FileMode(0750)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
items, err := ioutil.ReadDir(srcPath)
|
items, err := ioutil.ReadDir(srcPath)
|
||||||
|
@ -385,10 +385,10 @@ func matchGoldenFile(goldenFile string, actual []byte) error {
|
|||||||
// To update golden files, run the following:
|
// To update golden files, run the following:
|
||||||
// go test -v -run '^<Test-Name>$' github.com/matryer/moq/pkg/moq -update
|
// go test -v -run '^<Test-Name>$' github.com/matryer/moq/pkg/moq -update
|
||||||
if *update {
|
if *update {
|
||||||
if err := os.MkdirAll(filepath.Dir(goldenFile), 0755); err != nil {
|
if err := os.MkdirAll(filepath.Dir(goldenFile), 0750); err != nil {
|
||||||
return fmt.Errorf("create dir: %s", err)
|
return fmt.Errorf("create dir: %s", err)
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(goldenFile, actual, 0644); err != nil {
|
if err := ioutil.WriteFile(goldenFile, actual, 0600); err != nil {
|
||||||
return fmt.Errorf("write: %s", err)
|
return fmt.Errorf("write: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user