mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-14 07:08:06 +00:00
Fix for gosec rule G304 - sanitize filepaths
This commit is contained in:
parent
f67a83a5bc
commit
ffb6cbf769
@ -3,6 +3,7 @@ package yqlib
|
|||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
func safelyRenameFile(from string, to string) {
|
func safelyRenameFile(from string, to string) {
|
||||||
@ -25,7 +26,7 @@ func safelyRenameFile(from string, to string) {
|
|||||||
|
|
||||||
// thanks https://stackoverflow.com/questions/21060945/simple-way-to-copy-a-file-in-golang
|
// thanks https://stackoverflow.com/questions/21060945/simple-way-to-copy-a-file-in-golang
|
||||||
func copyFileContents(src, dst string) (err error) {
|
func copyFileContents(src, dst string) (err error) {
|
||||||
in, err := os.Open(src) // nolint gosec
|
in, err := os.Open(filepath.Clean(src))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"container/list"
|
"container/list"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
yaml "gopkg.in/yaml.v3"
|
yaml "gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
@ -13,7 +14,7 @@ func readStream(filename string) (io.Reader, error) {
|
|||||||
if filename == "-" {
|
if filename == "-" {
|
||||||
return bufio.NewReader(os.Stdin), nil
|
return bufio.NewReader(os.Stdin), nil
|
||||||
} else {
|
} else {
|
||||||
return os.Open(filename) // nolint gosec
|
return os.Open(filepath.Clean(filename))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@ -81,7 +82,7 @@ func WriteTempYamlFile(content string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ReadTempYamlFile(name string) string {
|
func ReadTempYamlFile(name string) string {
|
||||||
content, _ := ioutil.ReadFile(name)
|
content, _ := ioutil.ReadFile(filepath.Clean(name))
|
||||||
return string(content)
|
return string(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user