Compare commits

..

1 Commits

Author SHA1 Message Date
Belac Darkstorm a015b16293 Clean path before checking if valid. 2022-10-24 03:17:55 -05:00
3 changed files with 55 additions and 40 deletions
+1 -1
View File
@@ -220,13 +220,13 @@ func (f File) ExtractWithOptions(folder string, op ExtractionOptions) error {
func (f File) realExtract(folder string, op ExtractionOptions) error {
err := os.MkdirAll(folder, op.FolderPerm)
folder = filepath.Clean(folder)
if err != nil && !os.IsExist(err) {
if op.Verbose {
log.Println("Error while creating extraction folder")
}
return err
}
folder = filepath.Clean(folder)
if f.IsDir() {
filFS, _ := f.FS()
var ents []directory.Entry
+5 -5
View File
@@ -41,6 +41,7 @@ func (r Reader) newFS(e directory.Entry, parent *FS) (*FS, error) {
// Open opens the file at name. Returns a squashfs.File.
func (f FS) Open(name string) (fs.File, error) {
name = filepath.Clean(name)
if !fs.ValidPath(name) {
return nil, &fs.PathError{
Op: "open",
@@ -48,7 +49,6 @@ func (f FS) Open(name string) (fs.File, error) {
Err: fs.ErrInvalid,
}
}
name = filepath.Clean(name)
if name == "." || name == "" {
return f.File, nil
}
@@ -100,6 +100,7 @@ func (f FS) Open(name string) (fs.File, error) {
// All paths are relative to the FS.
// Uses filepath.Match to compare names.
func (f FS) Glob(pattern string) (out []string, err error) {
pattern = filepath.Clean(pattern)
if !fs.ValidPath(pattern) {
return nil, &fs.PathError{
Op: "glob",
@@ -107,7 +108,6 @@ func (f FS) Glob(pattern string) (out []string, err error) {
Err: fs.ErrInvalid,
}
}
pattern = filepath.Clean(pattern)
split := strings.Split(pattern, "/")
for i := 0; i < len(f.e); i++ {
if match, _ := path.Match(split[0], f.e[i].Name); match {
@@ -159,6 +159,7 @@ func (f FS) Glob(pattern string) (out []string, err error) {
// ReadDir returns all the DirEntry returns all DirEntry's for the directory at name.
// If name is not a directory, returns an error.
func (f FS) ReadDir(name string) ([]fs.DirEntry, error) {
name = filepath.Clean(name)
if !fs.ValidPath(name) {
return nil, &fs.PathError{
Op: "readdir",
@@ -166,7 +167,6 @@ func (f FS) ReadDir(name string) ([]fs.DirEntry, error) {
Err: fs.ErrInvalid,
}
}
name = filepath.Clean(name)
if name == "." || name == "" {
return f.File.ReadDir(-1)
}
@@ -258,6 +258,7 @@ func (f FS) ReadFile(name string) ([]byte, error) {
// Stat returns the fs.FileInfo for the file at name.
func (f FS) Stat(name string) (fs.FileInfo, error) {
name = filepath.Clean(strings.TrimPrefix(name, "/"))
if !fs.ValidPath(name) {
return nil, &fs.PathError{
Op: "stat",
@@ -265,7 +266,6 @@ func (f FS) Stat(name string) (fs.FileInfo, error) {
Err: fs.ErrInvalid,
}
}
name = filepath.Clean(strings.TrimPrefix(name, "/"))
if name == "." || name == "" {
return f.File.Stat()
}
@@ -327,6 +327,7 @@ func (f FS) Stat(name string) (fs.FileInfo, error) {
// Sub returns the FS at dir
func (f FS) Sub(dir string) (fs.FS, error) {
dir = filepath.Clean(dir)
if !fs.ValidPath(dir) {
return nil, &fs.PathError{
Op: "sub",
@@ -334,7 +335,6 @@ func (f FS) Sub(dir string) (fs.FS, error) {
Err: fs.ErrInvalid,
}
}
dir = filepath.Clean(dir)
if dir == "." || dir == "" {
return f, nil
}
+15
View File
@@ -57,6 +57,21 @@ func preTest(dir string) (fil *os.File, err error) {
return
}
func TestMisc(t *testing.T) {
tmpDir := "testing"
fil, err := preTest(tmpDir)
if err != nil {
t.Fatal(err)
}
rdr, err := squashfs.NewReader(fil)
if err != nil {
t.Fatal(err)
}
_ = rdr
// Put testing here
t.Fatal("UM")
}
func BenchmarkRace(b *testing.B) {
// tmpDir := b.TempDir()
tmpDir := "testing"